Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit d682b0c

Browse files
authored
Merge pull request #482 from ipfs/fix-online-cat
fix(cli): pipe content to the cli from cat it is a stream
2 parents 5d68188 + 5b8da13 commit d682b0c

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"detect-node": "^2.0.3",
6969
"glob": "^7.0.6",
7070
"hapi": "^15.0.3",
71-
"ipfs-api": "^8.0.3",
71+
"ipfs-api": "^8.0.4",
7272
"ipfs-bitswap": "^0.7.0",
7373
"ipfs-block": "^0.3.0",
7474
"ipfs-block-service": "^0.5.0",
@@ -132,4 +132,4 @@
132132
"nginnever <[email protected]>",
133133
"npmcdn-to-unpkg-bot <[email protected]>"
134134
]
135-
}
135+
}

src/cli/commands/files/add.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,17 @@ module.exports = {
5555
const index = inPath.lastIndexOf('/') + 1
5656

5757
utils.getIPFS((err, ipfs) => {
58-
if (err) throw err
58+
if (err) {
59+
throw err
60+
}
5961

6062
glob(path.join(inPath, '/**/*'), (err, list) => {
61-
if (err) throw err
62-
if (list.length === 0) list = [inPath]
63+
if (err) {
64+
throw err
65+
}
66+
if (list.length === 0) {
67+
list = [inPath]
68+
}
6369

6470
pull(
6571
zip(

src/cli/commands/files/cat.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,15 @@ module.exports = {
1818
if (err) {
1919
throw err
2020
}
21-
if (utils.isDaemonOn()) {
22-
ipfs.cat(path, (err, res) => {
23-
if (err) {
24-
throw err
25-
}
26-
console.log(res.toString())
27-
})
28-
return
29-
}
30-
ipfs.files.cat(path, (err, file) => {
31-
if (err) {
32-
throw (err)
33-
}
34-
file.pipe(process.stdout)
35-
})
21+
22+
ipfs.files.cat(path, onFile)
3623
})
3724
}
3825
}
26+
27+
function onFile (err, file) {
28+
if (err) {
29+
throw (err)
30+
}
31+
file.pipe(process.stdout)
32+
}

test/cli/test-files.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ describe('files', () => {
8080
.run((err, stdout, exitcode) => {
8181
expect(err).to.not.exist
8282
expect(exitcode).to.equal(0)
83+
expect(stdout[0]).to.equal('hello world')
8384
done()
8485
})
8586
})

0 commit comments

Comments
 (0)