Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 5bbe990

Browse files
committed
Add js implementation for #27
1 parent 119199c commit 5bbe990

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/fs.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,30 @@ function mkdir(path:string):Promise {
127127

128128
}
129129

130+
/**
131+
* Wrapper method of readStream.
132+
* @param {string} path Path of the file.
133+
* @param {'base64' | 'utf8' | 'ascii'} encoding Encoding of read stream.
134+
* @return {Promise<Array<number> | string>}
135+
*/
136+
function readFile(path:string, encoding:string, bufferSize:number):Promise<any> {
137+
return RNFetchBlob.readFile(path, encoding)
138+
}
139+
140+
function writeFile(path:string, encoding:string, data:string | Array<number>):Promise {
141+
if(encoding.toLocaleLowerCase() === 'ascii') {
142+
if(!Array.isArray(data))
143+
Promise.reject(`Expected "data" is an Array when encoding is "ascii", however got ${typeof data}`)
144+
else
145+
return RNFetchBlob.writeFileArray(path, data);
146+
} else {
147+
if(typeof data !== 'string')
148+
Promise.reject(`Expected "data" is a String when encoding is "utf8" or "base64", however got ${typeof data}`)
149+
else
150+
return RNFetchBlob.writeFile(path, encoding, data);
151+
}
152+
}
153+
130154
/**
131155
* Show statistic data of a path.
132156
* @param {string} path Target path

0 commit comments

Comments
 (0)