I'm writing a 5mo json in a file with utf8 encoding.
it take +-50ms with android
it take +-6000ms with ios iphone 5
reading the file take
250ms with android
13000ms with ios.
i get empty return when using base64 option on Ios only
my code :
var RNFS = require('react-native-fs');
const rootPath = RNFS.DocumentDirectoryPath; //= (os == "android") ? RNFS.DocumentDirectoryPath :RNFS.MainBundlePath
export function writeFile(filename, content) {
var path = rootPath + '/' + filename;
return RNFS.writeFile(path, content, 'base64').then(() => {
console.log('FILE WRITTEN!');
return true;
}).catch((err) => {
console.log(err.message);
return false;
});
}
export async function readFile(filename) {
var path = rootPath + '/' + filename;
var content = await RNFS.readFile(path, 'base64');
console.log("content before return", content );
return content;
}
and how i made the calls
async readFile() {
const content = await tools.readFile("en-test.js");
console.log("content", content);
}
async writeFile() {
const res = await tools.writeFile(
"en-test.js",
'Lorem ipsum dolor sit ametLorem ipsum dolor sit ametLorem ipsum dolor sit ametLorem ipsum dolor'
);
console.log("res", res);
}
I need to keep utf8, any advice ?
We definetely should move the utf8-encoding into native layer instead of using JS-layer therefor.
This should be implemented in upcoming versions
@itinance Firstly, thank you for all your work on the library!
I was wondering if there's a plan on moving the encoding into native on iOS? I did a very rudimentary test (literally just changed the default return type in the native code) and it looks like a 10x or greater speedup on large files.
All I did was swap [content base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]; with [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding];, but I haven't yet looked at Android or at the implications of changing the function signature to pass the encoding back to the native code.
Is this fixed?
Animations in my app stattering when I do RNFS.readFile
not fixed for me. read and write freeze complety the UI for many seconds. not usable unfortunably
Same here
+1
any update ?
I use RN-fetch-blob for read/write files
I use fetch to read/write files:
const res = await fetch(filePath);
const content = await res.text();
Can confirm that there is a significant difference between android and iOS.
This issue also affects e.g. the hash() function.
Edit: We were (and still are) actually using rn-fetch-blob. I was testing react-native-fs because our package was having issues. But this bug sent me straight back. Seems like a pretty big deal breaker to me.
I use
fetchto read/write files:const res = await fetch(filePath); const content = await res.text();
how did you write file with fetch ?
thanks
Can confirm that there is a significant difference between android and iOS.
This issue also affects e.g. the
hash()function.
I will test it today when i get the Mac back
Same problem. Downloading on iOS is extremely slow even on LAN connection.
uploadings getting slow with uri.
I also had to switch to rn-fetch-blob for iOS and Android due to the encoding happening in the JS Thread and in our case, blocking the App/Interactions for around 4 seconds.
Works fine with rn-fetch-blob which does the encoding natively
I'd move the encoding to native for this library with a PR, but atm I'm pretty occupied.
I got same situation when I read 3M file from IOS device. It takes 1.2 seconds to read it. I don't know what does it read file in js thread