Skip to content

Commit 99350d7

Browse files
committed
refactor: some refactoring in mfs
1 parent 0fb7c21 commit 99350d7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/mfs.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = function (options) {
6363
const readableStream = ipfs.files.readReadableStream(readPath)
6464

6565
readableStream.on('error', (error) => {
66-
if (error.toString().indexOf('does not exist') > -1 || error.toString().indexOf('Not a directory') > -1) {
66+
if (isNotFoundError(error)) {
6767
error.notFound = true
6868
}
6969
})
@@ -80,15 +80,15 @@ module.exports = function (options) {
8080

8181
log(`stat ${statPath}`)
8282
ipfs.files.stat(statPath, {}, (error) => {
83-
if (error) {
84-
if (error.toString().indexOf('does not exist') > -1 || error.toString().indexOf('Not a directory') > -1) {
85-
return cb(null, false)
86-
}
83+
if (!error) {
84+
return cb(null, true)
85+
}
8786

88-
return cb(error)
87+
if (isNotFoundError(error)) {
88+
return cb(null, false)
8989
}
9090

91-
cb(null, true)
91+
return cb(error)
9292
})
9393
}
9494

@@ -111,3 +111,7 @@ function noop () {}
111111
function normalisePath (path) {
112112
return path.replace(/\/(\/)+/g, '/')
113113
}
114+
115+
function isNotFoundError (error) {
116+
return error.toString().indexOf('does not exist') > -1 || error.toString().indexOf('Not a directory') > -1
117+
}

0 commit comments

Comments
 (0)