@@ -21,7 +21,7 @@ module.exports = function (options) {
21
21
}
22
22
23
23
store . createWriteStream = function ( opts , cb ) {
24
- if ( typeof opts === 'string' ) opts = { key : opts }
24
+ if ( typeof opts === 'string' ) opts = { key : opts }
25
25
if ( opts . name ) opts . key = opts . name
26
26
if ( ! cb ) cb = noop
27
27
@@ -54,7 +54,7 @@ module.exports = function (options) {
54
54
}
55
55
56
56
store . createReadStream = function ( opts ) {
57
- if ( typeof opts === 'string' ) opts = { key : opts }
57
+ if ( typeof opts === 'string' ) opts = { key : opts }
58
58
if ( opts . name ) opts . key = opts . name
59
59
60
60
const readPath = normalisePath ( store . baseDir + opts . key )
@@ -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
} )
@@ -72,28 +72,28 @@ module.exports = function (options) {
72
72
}
73
73
74
74
store . exists = function ( opts , cb ) {
75
- if ( typeof opts === 'string' ) opts = { key : opts }
75
+ if ( typeof opts === 'string' ) opts = { key : opts }
76
76
if ( opts . name ) opts . key = opts . name
77
77
if ( ! cb ) cb = noop
78
78
79
79
const statPath = normalisePath ( store . baseDir + opts . key )
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
95
95
store . remove = function ( opts , cb ) {
96
- if ( typeof opts === 'string' ) opts = { key : opts }
96
+ if ( typeof opts === 'string' ) opts = { key : opts }
97
97
if ( opts . name ) opts . key = opts . name
98
98
if ( ! cb ) cb = noop
99
99
@@ -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
+ }
0 commit comments