This repository was archived by the owner on Mar 16, 2019. It is now read-only.
This repository was archived by the owner on Mar 16, 2019. It is now read-only.
support strings in fs.readFile / fs.writeFile 'ascii' encoding (or add new encoding) #533
Open
Description
fs.readFile(path, 'ascii')
resolves to an array of numbers, which is different from the other encoding types ('base64'
and 'utf8'
resolve to string). This also differs from react-native-fs
(that library actually resolves to a binary string for the 'ascii'
encoding). So to work with binary strings with RNFetchBlob, we would have to convert the bytes back to a string with a loop like:
readFile(file, 'ascii').then((res) => {
const str = res.map(x => String.fromCharCode(x)).join("");
// ...
});
Similarly, writing binary data becomes messy:
const data = str.split("").map(x => x.charCodeAt(0));
writeFile(file, data, 'ascii');
Would it be more efficient to perform the binary string conversion in native code? If so, would it make sense to change the behavior of 'ascii'
or add a 'binary'
encoding that deals with "binary strings"?
ping @itinance -- any thoughts? does it make sense to similarly add a 'binary' alias in RNFS?