@@ -143,8 +143,11 @@ function pathForAppGroup(groupName:string):Promise {
143
143
*/
144
144
function readFile ( path :string , encoding :string ) :Promise < any > {
145
145
encoding = encoding || 'utf8'
146
- if ( typeof path !== 'string' )
147
- return Promise . reject ( new Error ( 'Invalid argument "path" ' ) )
146
+ if ( typeof path !== 'string' ) {
147
+ const err = new TypeError ( 'Missing argument "path" ' )
148
+ err . code = 'EINVAL'
149
+ return Promise . reject ( err )
150
+ }
148
151
return RNFetchBlob . readFile ( path , encoding )
149
152
}
150
153
@@ -215,6 +218,11 @@ function appendFile(path:string, data:string | Array<number>, encoding:?string):
215
218
*/
216
219
function stat ( path :string ) :Promise < RNFetchBlobFile > {
217
220
return new Promise ( ( resolve , reject ) => {
221
+ if ( typeof path !== 'string' ) {
222
+ const err = new TypeError ( 'Missing argument "path" ' )
223
+ err . code = 'EINVAL'
224
+ return reject ( err )
225
+ }
218
226
RNFetchBlob . stat ( path , ( err , stat ) => {
219
227
if ( err )
220
228
reject ( new Error ( err ) )
@@ -246,6 +254,11 @@ function scanFile(pairs:any):Promise {
246
254
}
247
255
248
256
function hash ( path : string , algorithm : string ) : Promise < string > {
257
+ if ( typeof path !== 'string' || typeof algorithm !== 'string' ) {
258
+ const err = new TypeError ( 'Missing argument "path" and/or "algorithm"' )
259
+ err . code = 'EINVAL'
260
+ return Promise . reject ( err )
261
+ }
249
262
return RNFetchBlob . hash ( path , algorithm )
250
263
}
251
264
@@ -283,7 +296,12 @@ function lstat(path:string):Promise<Array<RNFetchBlobFile>> {
283
296
}
284
297
285
298
function ls ( path :string ) :Promise < Array < String >> {
286
- return RNFetchBlob . ls ( path )
299
+ if ( typeof path !== 'string' ) {
300
+ const err = new TypeError ( 'Missing argument "path" ' )
301
+ err . code = 'EINVAL'
302
+ return Promise . reject ( err )
303
+ }
304
+ return RNFetchBlob . ls ( path )
287
305
}
288
306
289
307
/**
0 commit comments