From 2eda8e0fcde65691cecfaf51dbffe14049954a5b Mon Sep 17 00:00:00 2001 From: nginnever Date: Tue, 7 Jun 2016 03:09:04 -0700 Subject: [PATCH 1/2] cat interface-core upgrades --- package.json | 4 ++-- src/cli/commands/files/cat.js | 6 ++---- src/core/index.js | 1 + src/core/ipfs/files.js | 13 ++++++++++--- src/http-api/resources/files.js | 2 +- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 97f17e1bf2..89580e7954 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "form-data": "^1.0.0-rc3", "gulp": "^3.9.1", "idb-plus-blob-store": "^1.1.2", - "interface-ipfs-core": "^0.2.2", + "interface-ipfs-core": "^0.3.0", "left-pad": "^1.1.0", "lodash": "^4.11.2", "mocha": "^2.5.1", @@ -67,7 +67,7 @@ "glob": "^7.0.3", "hapi": "^13.4.1", "ipfs-bitswap": "^0.4.1", - "ipfs-api": "^5.0.1", + "ipfs-api": "^6.0.1", "ipfs-block": "^0.3.0", "ipfs-block-service": "^0.4.0", "ipfs-merkle-dag": "^0.6.0", diff --git a/src/cli/commands/files/cat.js b/src/cli/commands/files/cat.js index dfb8c175f0..ff87a82a69 100644 --- a/src/cli/commands/files/cat.js +++ b/src/cli/commands/files/cat.js @@ -31,13 +31,11 @@ module.exports = Command.extend({ }) return } - ipfs.files.cat(path, (err, res) => { + ipfs.files.cat(path, (err, file) => { if (err) { throw (err) } - res.on('data', (data) => { - data.content.pipe(process.stdout) - }) + file.pipe(process.stdout) }) }) } diff --git a/src/core/index.js b/src/core/index.js index e6d1d3be32..4ac3b388d0 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -57,5 +57,6 @@ function IPFS (repoInstance) { this.object = object(this) this.libp2p = libp2p(this) this.files = files(this) + this.cat = files(this).cat // Alias for js-ipfs-api cat this.bitswap = bitswap(this) } diff --git a/src/core/ipfs/files.js b/src/core/ipfs/files.js index 298eb14219..4d1e972484 100644 --- a/src/core/ipfs/files.js +++ b/src/core/ipfs/files.js @@ -100,7 +100,11 @@ module.exports = function files (self) { i.end() }), - cat: (hash, callback) => { + cat: promisify((hash, callback) => { + if (typeof hash === 'function') { + callback = hash + return callback('You must supply a multihash', null) + } self._dagS.get(hash, (err, fetchedNode) => { if (err) { return callback(err, null) @@ -110,10 +114,13 @@ module.exports = function files (self) { callback('This dag node is a directory', null) } else { const exportStream = Exporter(hash, self._dagS) - callback(null, exportStream) + exportStream.once('data', (object) => { + callback(null, object.content) + }) } }) - }, + }), + get: (hash, callback) => { var exportFile = Exporter(hash, self._dagS) callback(null, exportFile) diff --git a/src/http-api/resources/files.js b/src/http-api/resources/files.js index 3ebe82f5b1..f4b8f14dd2 100644 --- a/src/http-api/resources/files.js +++ b/src/http-api/resources/files.js @@ -43,7 +43,7 @@ exports.cat = { }).code(500) } stream.on('data', (data) => { - return reply(data.content) + return reply(data) }) }) } From 48937730c6c45cd25400cc36a640c5f522aaca81 Mon Sep 17 00:00:00 2001 From: nginnever Date: Tue, 7 Jun 2016 03:25:10 -0700 Subject: [PATCH 2/2] CR updates --- src/core/ipfs/files.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/ipfs/files.js b/src/core/ipfs/files.js index 4d1e972484..0184147d57 100644 --- a/src/core/ipfs/files.js +++ b/src/core/ipfs/files.js @@ -102,16 +102,15 @@ module.exports = function files (self) { cat: promisify((hash, callback) => { if (typeof hash === 'function') { - callback = hash - return callback('You must supply a multihash', null) + return callback(new Error('You must supply a multihash')) } self._dagS.get(hash, (err, fetchedNode) => { if (err) { - return callback(err, null) + return callback(err) } const data = UnixFS.unmarshal(fetchedNode.data) if (data.type === 'directory') { - callback('This dag node is a directory', null) + callback(new Error('This dag node is a directory')) } else { const exportStream = Exporter(hash, self._dagS) exportStream.once('data', (object) => {