Skip to content

Commit 30af8e9

Browse files
committed
more parameter checks
1 parent 0bac254 commit 30af8e9

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

fs.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,11 @@ function pathForAppGroup(groupName:string):Promise {
143143
*/
144144
function readFile(path:string, encoding:string):Promise<any> {
145145
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+
}
148151
return RNFetchBlob.readFile(path, encoding)
149152
}
150153

@@ -215,6 +218,11 @@ function appendFile(path:string, data:string | Array<number>, encoding:?string):
215218
*/
216219
function stat(path:string):Promise<RNFetchBlobFile> {
217220
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+
}
218226
RNFetchBlob.stat(path, (err, stat) => {
219227
if(err)
220228
reject(new Error(err))
@@ -246,6 +254,11 @@ function scanFile(pairs:any):Promise {
246254
}
247255

248256
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+
}
249262
return RNFetchBlob.hash(path, algorithm)
250263
}
251264

@@ -283,7 +296,12 @@ function lstat(path:string):Promise<Array<RNFetchBlobFile>> {
283296
}
284297

285298
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)
287305
}
288306

289307
/**

0 commit comments

Comments
 (0)