This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
block.put ignores CID argument #815
Closed
Description
Hello, I'm having an issue where block.get
is hanging and never returns the block.
Here's the example code:
const ipfsAPI = require('ipfs-api')
const CID = require('cids')
const multihashes = require('multihashes')
const crypto = require('crypto')
function sha256(data) {
return crypto.createHash('sha256').update(data).digest()
}
const ipfs = ipfsAPI('localhost', '5001', {protocol: 'http'})
const buf = sha256('hello world!')
const mh = multihashes.encode(buf, 'sha2-256')
const cid = new CID(1, 'dag-cbor', mh)
console.log('cid', cid.toBaseEncodedString())
ipfs.repo.gc()
.then(() => {
return ipfs.block.put(buf, cid)
.then(block => {
console.log('put', block.cid.toBaseEncodedString())
return ipfs.block.get(cid)
.then(block => {
// Never gets called!
console.log('get', block._data.toString())
})
.catch(error => console.error(error))
})
})
Output
cid zdpuAtJJwFer98hHGdt2UQdoF1We7vQuBXSTDKjorNkYovyzQ
put QmPdbXGenToPFzmxJyoVNAAfh5eKvnu2f8KzSx2J8jhwQP
It works using the CLI though:
$ ipfs repo gc
$ echo -n 'hello world!' | ipfs block put -f cbor
zdpuAtJJwFer98hHGdt2UQdoF1We7vQuBXSTDKjorNkYovyzQ
$ ipfs block get zdpuAtJJwFer98hHGdt2UQdoF1We7vQuBXSTDKjorNkYovyzQ
hello world!
Any help is appreciated, thanks.