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

Commit 9ed6eae

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

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-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

+22-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')
67

78
module.exports = (send) => {
89
return {
910
get: promisify((args, opts, callback) => {
11+
// TODO this needs to be adjusted with the new go-ipfs
12+
// http-api
13+
if (args.constructor && args.constructor.name === 'CID') {
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,12 @@ module.exports = (send) => {
3239
})
3340
}),
3441
stat: promisify((args, opts, callback) => {
42+
// TODO this needs to be adjusted with the new go-ipfs
43+
// http-api
44+
if (opts.constructor && opts.constructor.name === 'CID') {
45+
opts = {}
46+
}
47+
3548
if (typeof (opts) === 'function') {
3649
callback = opts
3750
opts = {}
@@ -50,7 +63,15 @@ module.exports = (send) => {
5063
})
5164
})
5265
}),
53-
put: promisify((block, callback) => {
66+
put: promisify((block, cid, callback) => {
67+
// TODO this needs to be adjusted with the new go-ipfs
68+
// http-api
69+
70+
if (typeof (cid) === 'function') {
71+
callback = cid
72+
cid = {}
73+
}
74+
5475
if (Array.isArray(block)) {
5576
const err = new Error('block.put() only accepts 1 file')
5677
return callback(err)

0 commit comments

Comments
 (0)