From 3e4e2fd9ed0a098c8f53c6d0f6c574976f224152 Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Mon, 12 Sep 2016 22:21:43 +0200 Subject: [PATCH 1/3] fix(cli): pipe content to the cli from cat it is a stream --- src/cli/commands/files/cat.js | 12 +++--------- test/cli/test-files.js | 1 + 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/cli/commands/files/cat.js b/src/cli/commands/files/cat.js index 34737439ae..e2be436765 100644 --- a/src/cli/commands/files/cat.js +++ b/src/cli/commands/files/cat.js @@ -14,23 +14,17 @@ module.exports = { handler (argv) { const path = argv['ipfs-path'] + utils.getIPFS((err, ipfs) => { if (err) { throw err } - if (utils.isDaemonOn()) { - ipfs.cat(path, (err, res) => { - if (err) { - throw err - } - console.log(res.toString()) - }) - return - } + ipfs.files.cat(path, (err, file) => { if (err) { throw (err) } + file.pipe(process.stdout) }) }) diff --git a/test/cli/test-files.js b/test/cli/test-files.js index a9a5bf68cb..572c6fffec 100644 --- a/test/cli/test-files.js +++ b/test/cli/test-files.js @@ -80,6 +80,7 @@ describe('files', () => { .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) + expect(stdout[0]).to.equal('hello world') done() }) }) From 4e619584ace3b78f67be10c92f1a1a491abc90fc Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Mon, 12 Sep 2016 23:05:11 +0200 Subject: [PATCH 2/3] there is no cat --- src/cli/commands/files/cat.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cli/commands/files/cat.js b/src/cli/commands/files/cat.js index e2be436765..a28a22e6e9 100644 --- a/src/cli/commands/files/cat.js +++ b/src/cli/commands/files/cat.js @@ -14,19 +14,23 @@ module.exports = { handler (argv) { const path = argv['ipfs-path'] - utils.getIPFS((err, ipfs) => { if (err) { throw err } - ipfs.files.cat(path, (err, file) => { - if (err) { - throw (err) - } + if (utils.isDaemonOn()) { + return ipfs.cat(path, onFile) + } - file.pipe(process.stdout) - }) + ipfs.files.cat(path, onFile) }) } } + +function onFile (err, file) { + if (err) { + throw (err) + } + file.pipe(process.stdout) +} From 5b8da135c0bc7b675bac77bb708c95d699db421c Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 12 Sep 2016 19:39:01 -0400 Subject: [PATCH 3/3] fix: always use files.cat --- package.json | 4 ++-- src/cli/commands/files/add.js | 12 +++++++++--- src/cli/commands/files/cat.js | 4 ---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index fc8f27f53f..7355b74bf4 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "detect-node": "^2.0.3", "glob": "^7.0.6", "hapi": "^15.0.3", - "ipfs-api": "^8.0.3", + "ipfs-api": "^8.0.4", "ipfs-bitswap": "^0.7.0", "ipfs-block": "^0.3.0", "ipfs-block-service": "^0.5.0", @@ -132,4 +132,4 @@ "nginnever ", "npmcdn-to-unpkg-bot " ] -} \ No newline at end of file +} diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index eb13ac1cb9..047fd34c91 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -55,11 +55,17 @@ module.exports = { const index = inPath.lastIndexOf('/') + 1 utils.getIPFS((err, ipfs) => { - if (err) throw err + if (err) { + throw err + } glob(path.join(inPath, '/**/*'), (err, list) => { - if (err) throw err - if (list.length === 0) list = [inPath] + if (err) { + throw err + } + if (list.length === 0) { + list = [inPath] + } pull( zip( diff --git a/src/cli/commands/files/cat.js b/src/cli/commands/files/cat.js index a28a22e6e9..7c16b9aa6e 100644 --- a/src/cli/commands/files/cat.js +++ b/src/cli/commands/files/cat.js @@ -19,10 +19,6 @@ module.exports = { throw err } - if (utils.isDaemonOn()) { - return ipfs.cat(path, onFile) - } - ipfs.files.cat(path, onFile) }) }