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 21, 2016
1 parent 5cd59a8 commit 9a99d5a
Show file tree
Hide file tree
Showing 2 changed files with 24 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"
}
}
23 changes: 22 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')

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

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

if (typeof (opts) === 'function') {
callback = opts
opts = {}
Expand All @@ -50,7 +63,15 @@ 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 9a99d5a

Please sign in to comment.