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

Commit

Permalink
fix: files.cat: detect and handle rrors when unknown path and cat dir (
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte authored and richardschneider committed Dec 17, 2017
1 parent 295abe9 commit e6d825c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"progress": "^2.0.0",
"promisify-es6": "^1.0.3",
"pull-abortable": "^4.1.1",
"pull-defer": "^0.2.2",
"pull-file": "^1.1.0",
"pull-ndjson": "^0.1.1",
"pull-paramap": "^1.2.2",
Expand Down
22 changes: 13 additions & 9 deletions src/core/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ module.exports = function files (self) {
pull.collect((err, files) => {
if (err) { d.end(err) }
if (!files || !files.length) {
return d.end(new Error('No such file'))
return d.abort(new Error('No such file'))
}

const content = files[files.length - 1].content
if (files.length > 1) {
files = files.filter((file) => file.path === ipfsPath)
}

const file = files[0]

const content = file.content
if (!content && file.type === 'dir') {
return d.abort(new Error('this dag node is a directory'))
}
d.resolve(content)
})
)
Expand Down Expand Up @@ -206,21 +215,16 @@ module.exports = function files (self) {
addPullStream: _addPullStream,

cat: promisify((ipfsPath, callback) => {
const p = _catPullStream(ipfsPath)
pull(
p,
_catPullStream(ipfsPath),
pull.collect((err, buffers) => {
if (err) { return callback(err) }
callback(null, Buffer.concat(buffers))
})
)
}),

catReadableStream: (ipfsPath) => {
const p = _catPullStream(ipfsPath)

return toStream.source(p)
},
catReadableStream: (ipfsPath) => toStream.source(_catPullStream(ipfsPath)),

catPullStream: _catPullStream,

Expand Down

0 comments on commit e6d825c

Please sign in to comment.