File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ module.exports = function (options) {
63
63
const readableStream = ipfs . files . readReadableStream ( readPath )
64
64
65
65
readableStream . on ( 'error' , ( error ) => {
66
- if ( error . toString ( ) . indexOf ( 'does not exist' ) > - 1 || error . toString ( ) . indexOf ( 'Not a directory' ) > - 1 ) {
66
+ if ( isNotFoundError ( error ) ) {
67
67
error . notFound = true
68
68
}
69
69
} )
@@ -80,15 +80,15 @@ module.exports = function (options) {
80
80
81
81
log ( `stat ${ statPath } ` )
82
82
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
+ }
87
86
88
- return cb ( error )
87
+ if ( isNotFoundError ( error ) ) {
88
+ return cb ( null , false )
89
89
}
90
90
91
- cb ( null , true )
91
+ return cb ( error )
92
92
} )
93
93
}
94
94
@@ -111,3 +111,7 @@ function noop () {}
111
111
function normalisePath ( path ) {
112
112
return path . replace ( / \/ ( \/ ) + / g, '/' )
113
113
}
114
+
115
+ function isNotFoundError ( error ) {
116
+ return error . toString ( ) . indexOf ( 'does not exist' ) > - 1 || error . toString ( ) . indexOf ( 'Not a directory' ) > - 1
117
+ }
You can’t perform that action at this time.
0 commit comments