diff --git a/package.json b/package.json index dd26a582d..aaa11a6fd 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "lodash": "^4.17.11", "lru-cache": "^4.1.3", "multiaddr": "^5.0.2", - "multibase": "~0.5.0", + "multibase": "~0.6.0", "multihashes": "~0.4.14", "ndjson": "^1.5.0", "once": "^1.4.0", @@ -85,7 +85,7 @@ "eslint-plugin-react": "^7.11.1", "go-ipfs-dep": "~0.4.18", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.87.0", + "interface-ipfs-core": "~0.88.0", "ipfsd-ctl": "~0.40.0", "nock": "^10.0.2", "pull-stream": "^3.6.9", diff --git a/src/object/addLink.js b/src/object/addLink.js index d586d73d7..3ed3c7bc5 100644 --- a/src/object/addLink.js +++ b/src/object/addLink.js @@ -1,11 +1,10 @@ 'use strict' const promisify = require('promisify-es6') +const CID = require('cids') const cleanMultihash = require('../utils/clean-multihash') module.exports = (send) => { - const objectGet = require('./get')(send) - return promisify((multihash, dLink, opts, callback) => { if (typeof opts === 'function') { callback = opts @@ -32,7 +31,7 @@ module.exports = (send) => { if (err) { return callback(err) } - objectGet(result.Hash, { enc: 'base58' }, callback) + callback(null, new CID(result.Hash)) }) }) } diff --git a/src/object/appendData.js b/src/object/appendData.js index fa3783909..1fe4ce695 100644 --- a/src/object/appendData.js +++ b/src/object/appendData.js @@ -2,11 +2,11 @@ const promisify = require('promisify-es6') const once = require('once') +const CID = require('cids') const cleanMultihash = require('../utils/clean-multihash') const SendOneFile = require('../utils/send-one-file') module.exports = (send) => { - const objectGet = require('./get')(send) const sendOneFile = SendOneFile(send, 'object/patch/append-data') return promisify((multihash, data, opts, _callback) => { @@ -30,7 +30,7 @@ module.exports = (send) => { return callback(err) } - objectGet(result.Hash, { enc: 'base58' }, callback) + callback(null, new CID(result.Hash)) }) }) } diff --git a/src/object/links.js b/src/object/links.js index 9b4f6284e..943509e67 100644 --- a/src/object/links.js +++ b/src/object/links.js @@ -4,7 +4,6 @@ const promisify = require('promisify-es6') const dagPB = require('ipld-dag-pb') const DAGLink = dagPB.DAGLink const cleanMultihash = require('../utils/clean-multihash') -const bs58 = require('bs58') const LRU = require('lru-cache') const lruOptions = { max: 128 @@ -46,7 +45,7 @@ module.exports = (send) => { if (result.Links) { links = result.Links.map((l) => { - return new DAGLink(l.Name, l.Size, Buffer.from(bs58.decode(l.Hash))) + return new DAGLink(l.Name, l.Size, l.Hash) }) } callback(null, links) diff --git a/src/object/new.js b/src/object/new.js index 351e7b885..f9d8ddb35 100644 --- a/src/object/new.js +++ b/src/object/new.js @@ -1,9 +1,7 @@ 'use strict' const promisify = require('promisify-es6') -const dagPB = require('ipld-dag-pb') -const DAGNode = dagPB.DAGNode -const Unixfs = require('ipfs-unixfs') +const CID = require('cids') module.exports = (send) => { return promisify((template, callback) => { @@ -19,24 +17,7 @@ module.exports = (send) => { return callback(err) } - let data - - if (template) { - if (template !== 'unixfs-dir') { - return callback(new Error('unkown template: ' + template)) - } - data = (new Unixfs('directory')).marshal() - } else { - data = Buffer.alloc(0) - } - - DAGNode.create(data, (err, node) => { - if (err) { - return callback(err) - } - - callback(null, node) - }) + callback(null, new CID(result.Hash)) }) }) } diff --git a/src/object/put.js b/src/object/put.js index 2d4f8ad5a..0b624f7f9 100644 --- a/src/object/put.js +++ b/src/object/put.js @@ -1,14 +1,9 @@ 'use strict' const promisify = require('promisify-es6') -const dagPB = require('ipld-dag-pb') -const DAGNode = dagPB.DAGNode -const LRU = require('lru-cache') -const lruOptions = { - max: 128 -} +const CID = require('cids') +const { DAGNode } = require('ipld-dag-pb') -const cache = LRU(lruOptions) const SendOneFile = require('../utils/send-one-file') const once = require('once') @@ -72,49 +67,7 @@ module.exports = (send) => { return callback(err) // early } - if (Buffer.isBuffer(obj)) { - if (!options.enc) { - obj = { Data: obj, Links: [] } - } else if (options.enc === 'json') { - obj = JSON.parse(obj.toString()) - } - } - - let node - - if (DAGNode.isDAGNode(obj)) { - node = obj - } else if (options.enc === 'protobuf') { - dagPB.util.deserialize(obj, (err, _node) => { - if (err) { - return callback(err) - } - node = _node - next() - }) - return - } else { - DAGNode.create(Buffer.from(obj.Data), obj.Links, (err, _node) => { - if (err) { - return callback(err) - } - node = _node - next() - }) - return - } - next() - - function next () { - dagPB.util.cid(node, (err, cid) => { - if (err) { - return callback(err) - } - - cache.set(cid.toBaseEncodedString(), node) - callback(null, node) - }) - } + callback(null, new CID(result.Hash)) }) }) } diff --git a/src/object/rmLink.js b/src/object/rmLink.js index d127af1ab..3a45529cf 100644 --- a/src/object/rmLink.js +++ b/src/object/rmLink.js @@ -1,11 +1,10 @@ 'use strict' const promisify = require('promisify-es6') +const CID = require('cids') const cleanMultihash = require('../utils/clean-multihash') module.exports = (send) => { - const objectGet = require('./get')(send) - return promisify((multihash, dLink, opts, callback) => { if (typeof opts === 'function') { callback = opts @@ -31,7 +30,7 @@ module.exports = (send) => { if (err) { return callback(err) } - objectGet(result.Hash, { enc: 'base58' }, callback) + callback(null, new CID(result.Hash)) }) }) } diff --git a/src/object/setData.js b/src/object/setData.js index a4296dddd..7a256ca11 100644 --- a/src/object/setData.js +++ b/src/object/setData.js @@ -2,11 +2,11 @@ const promisify = require('promisify-es6') const once = require('once') +const CID = require('cids') const cleanMultihash = require('../utils/clean-multihash') const SendOneFile = require('../utils/send-one-file') module.exports = (send) => { - const objectGet = require('./get')(send) const sendOneFile = SendOneFile(send, 'object/patch/set-data') return promisify((multihash, data, opts, _callback) => { @@ -29,7 +29,7 @@ module.exports = (send) => { if (err) { return callback(err) } - objectGet(result.Hash, { enc: 'base58' }, callback) + callback(null, new CID(result.Hash)) }) }) } diff --git a/test/log.spec.js b/test/log.spec.js index 1d6432f57..38f9cf58c 100644 --- a/test/log.spec.js +++ b/test/log.spec.js @@ -32,7 +32,7 @@ describe('.log', function () { it('.log.tail', (done) => { let i = setInterval(() => { - ipfs.files.add(Buffer.from('just adding some data to generate logs')) + ipfs.add(Buffer.from('just adding some data to generate logs')) }, 1000) const req = ipfs.log.tail((err, res) => {