The readAsText
function of the cordova-file-plugin causes an encoding error when reading an UTF-8 file larger than 2 megabytes on platforms iOS, Android and Windows.
The error is caused by the native implementation of the readAsText
function of the cordova-file-plugin
. Files are cut into chunks at a predefined size and are immediately converted to UTF-8. UTF-8 encoded characters use 4 bytes and if the cut is exactly at one character with 4 bytes, an encoding error is thrown.
You can see the UTF-8 leading byte e2
at the end of data-chunk.dump file.
We implemented a workaround using the readAsArrayBuffer
function of the cordova-file-plugin
and converting the typed array to UTF-8 in JavaScript with TextDecoder.decode().
- Install dependencies first
npm i
- Initialize Cordova
npm run init
- Deploy on platform
npm run ios/android/windows
- Press
Fire Parser
in Demo App - Watch the logs
- Set a breakpoint at the throw of encoding error in iOS
- Look at the
data
variable