@@ -21,7 +21,7 @@ module.exports = function (options) {
2121 }
2222
2323 store . createWriteStream = function ( opts , cb ) {
24- if ( typeof opts === 'string' ) opts = { key : opts }
24+ if ( typeof opts === 'string' ) opts = { key : opts }
2525 if ( opts . name ) opts . key = opts . name
2626 if ( ! cb ) cb = noop
2727
@@ -54,7 +54,7 @@ module.exports = function (options) {
5454 }
5555
5656 store . createReadStream = function ( opts ) {
57- if ( typeof opts === 'string' ) opts = { key : opts }
57+ if ( typeof opts === 'string' ) opts = { key : opts }
5858 if ( opts . name ) opts . key = opts . name
5959
6060 const readPath = normalisePath ( store . baseDir + opts . key )
@@ -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 } )
@@ -72,28 +72,28 @@ module.exports = function (options) {
7272 }
7373
7474 store . exists = function ( opts , cb ) {
75- if ( typeof opts === 'string' ) opts = { key : opts }
75+ if ( typeof opts === 'string' ) opts = { key : opts }
7676 if ( opts . name ) opts . key = opts . name
7777 if ( ! cb ) cb = noop
7878
7979 const statPath = normalisePath ( store . baseDir + opts . key )
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
9595 store . remove = function ( opts , cb ) {
96- if ( typeof opts === 'string' ) opts = { key : opts }
96+ if ( typeof opts === 'string' ) opts = { key : opts }
9797 if ( opts . name ) opts . key = opts . name
9898 if ( ! cb ) cb = noop
9999
@@ -111,3 +111,7 @@ function noop () {}
111111function 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