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

Commit

Permalink
feat: support new CID block API
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Oct 25, 2016
1 parent 5cd59a8 commit 4314815
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ipfs-api",
"version": "9.0.0",
"description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec",
"main": "lib/index.js",
"main": "src/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"test": "node --max_old_space_size=4096 node_modules/.bin/gulp test:node",
Expand Down Expand Up @@ -103,4 +103,4 @@
"url": "https://github.com/ipfs/js-ipfs-api/issues"
},
"homepage": "https://github.com/ipfs/js-ipfs-api"
}
}
20 changes: 19 additions & 1 deletion src/api/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
const promisify = require('promisify-es6')
const bl = require('bl')
const Block = require('ipfs-block')
const multihash = require('multihashes')
const CID = require('cids')

module.exports = (send) => {
return {
get: promisify((args, opts, callback) => {
// TODO this needs to be adjusted with the new go-ipfs http-api
if (args && CID.isCID(args)) {
args = multihash.toB58String(args.multihash)
}
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

return send({
path: 'block/get',
args: args,
Expand All @@ -32,6 +39,11 @@ module.exports = (send) => {
})
}),
stat: promisify((args, opts, callback) => {
// TODO this needs to be adjusted with the new go-ipfs http-api
if (args && CID.isCID(args)) {
args = multihash.toB58String(args.multihash)
}

if (typeof (opts) === 'function') {
callback = opts
opts = {}
Expand All @@ -50,7 +62,13 @@ module.exports = (send) => {
})
})
}),
put: promisify((block, callback) => {
put: promisify((block, cid, callback) => {
// TODO this needs to be adjusted with the new go-ipfs http-api
if (typeof cid === 'function') {
callback = cid
cid = {}
}

if (Array.isArray(block)) {
const err = new Error('block.put() only accepts 1 file')
return callback(err)
Expand Down

0 comments on commit 4314815

Please sign in to comment.