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

Awesome IPLD Endeavour #398

Merged
merged 4 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: support new CID block API
  • Loading branch information
daviddias committed Oct 25, 2016
commit 43148150ec65d143481f6fab6e78bae461b8d745
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: remove before merge

"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