Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit b560d33

Browse files
dignifiedquiredaviddias
authored andcommitted
update for new block interface
1 parent 909f368 commit b560d33

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/api/block.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ module.exports = (send) => {
1010
return {
1111
get: promisify((args, opts, callback) => {
1212
// TODO this needs to be adjusted with the new go-ipfs http-api
13+
let cid
1314
if (CID.isCID(args)) {
15+
cid = args
1416
args = multihash.toB58String(args.multihash)
15-
}
16-
if (Buffer.isBuffer(args)) {
17+
} else if (Buffer.isBuffer(args)) {
18+
cid = new CID(args)
1719
args = multihash.toB58String(args)
20+
} else if (typeof args == 'string') {
21+
cid = new CID(args)
22+
} else {
23+
return callback(new Error('invalid argument'))
1824
}
25+
1926
if (typeof opts === 'function') {
2027
callback = opts
2128
opts = {}
@@ -24,13 +31,13 @@ module.exports = (send) => {
2431
// Transform the response from Buffer or a Stream to a Block
2532
const transform = (res, callback) => {
2633
if (Buffer.isBuffer(res)) {
27-
callback(null, new Block(res))
34+
callback(null, new Block(res, cid))
2835
} else {
2936
streamToValue(res, (err, data) => {
3037
if (err) {
3138
return callback(err)
3239
}
33-
callback(null, new Block(data))
40+
callback(null, new Block(data, cid))
3441
})
3542
}
3643
}
@@ -92,7 +99,9 @@ module.exports = (send) => {
9299
}
93100

94101
// Transform the response to a Block
95-
const transform = (blockInfo, callback) => callback(null, new Block(block))
102+
const transform = (info, callback) => {
103+
callback(null, new Block(block, new CID(info.Key)))
104+
}
96105

97106
send.andTransform(request, transform, callback)
98107
})

0 commit comments

Comments
 (0)