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

Commit 4314815

Browse files
committed
feat: support new CID block API
1 parent 5cd59a8 commit 4314815

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ipfs-api",
33
"version": "9.0.0",
44
"description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec",
5-
"main": "lib/index.js",
5+
"main": "src/index.js",
66
"jsnext:main": "src/index.js",
77
"scripts": {
88
"test": "node --max_old_space_size=4096 node_modules/.bin/gulp test:node",
@@ -103,4 +103,4 @@
103103
"url": "https://github.com/ipfs/js-ipfs-api/issues"
104104
},
105105
"homepage": "https://github.com/ipfs/js-ipfs-api"
106-
}
106+
}

src/api/block.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
const promisify = require('promisify-es6')
44
const bl = require('bl')
55
const Block = require('ipfs-block')
6+
const multihash = require('multihashes')
7+
const CID = require('cids')
68

79
module.exports = (send) => {
810
return {
911
get: promisify((args, opts, callback) => {
12+
// TODO this needs to be adjusted with the new go-ipfs http-api
13+
if (args && CID.isCID(args)) {
14+
args = multihash.toB58String(args.multihash)
15+
}
1016
if (typeof (opts) === 'function') {
1117
callback = opts
1218
opts = {}
1319
}
20+
1421
return send({
1522
path: 'block/get',
1623
args: args,
@@ -32,6 +39,11 @@ module.exports = (send) => {
3239
})
3340
}),
3441
stat: promisify((args, opts, callback) => {
42+
// TODO this needs to be adjusted with the new go-ipfs http-api
43+
if (args && CID.isCID(args)) {
44+
args = multihash.toB58String(args.multihash)
45+
}
46+
3547
if (typeof (opts) === 'function') {
3648
callback = opts
3749
opts = {}
@@ -50,7 +62,13 @@ module.exports = (send) => {
5062
})
5163
})
5264
}),
53-
put: promisify((block, callback) => {
65+
put: promisify((block, cid, callback) => {
66+
// TODO this needs to be adjusted with the new go-ipfs http-api
67+
if (typeof cid === 'function') {
68+
callback = cid
69+
cid = {}
70+
}
71+
5472
if (Array.isArray(block)) {
5573
const err = new Error('block.put() only accepts 1 file')
5674
return callback(err)

0 commit comments

Comments
 (0)