'Failed to convert data to 'utf8' encoded string' with RNFetchBlob.fs.readStream #593
Description
Hi! I am trying to read a CSV file with RNFetchBlob.fs.readStream
, but keep getting this error:
Failed to convert data to 'utf8' encoded string, this might due to the source data is not able to convert using this encoding. source = *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]
Curious thing is, that when I use readFile()
instead of readStream()
, the operation runs just fine and I get a result. The problem is, I would like to use readStream()
because some of the files I need to read are too big to be efficiently handled by readFile()
.
Also, other files in the same directory and with the same format can be processed with both readFile()
and readStream()
.
Here is my code:
readFiles(path) {
let data ='';
RNFetchBlob.fs.readStream(`${path}/trips.txt`, 'utf8')
.then((ifstream) => {
ifstream.open();
ifstream.onData((chunk) => {
data += chunk;
});
ifstream.onError((err) => {
console.log(err);
});
ifstream.onEnd(() => {
this.processCSVData(data);
});
}).catch((err) => {
console.log(err);
});
}
This is the part that works on some files and does not work on others (for example the trips.txt). I have not found anything that makes the files that work different from the files that don't. Worth noting is, that it always crashes inside the readStream()
call, without ever getting to any of the callbacks.
What always works (except for very large files, obviously :-) ), is this:
RNFetchBlob.fs.readFile(`${path}/trips.txt`, 'utf8').then((contents) => {
this.processCSVData(contents);
});
my RN and RNFetchBlob versions:
"react-native": "0.50.1",
"react-native-fetch-blob": "^0.10.8",
Any help is appreciated.
Thanks!