Skip to content

A Cordova project to reproduce utf-8 encoding bug in the cordova-file-plugin

Notifications You must be signed in to change notification settings

chauthai/cordova-file-plugin-bug-report

Repository files navigation

cordova-file-plugin encoding error bug report

Abstract

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.

Description

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.

Workaround

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().

How to reproduce the encoding error

  1. Install dependencies first npm i
  2. Initialize Cordova npm run init
  3. Deploy on platform npm run ios/android/windows
  4. Press Fire Parser in Demo App
  5. Watch the logs
  6. Set a breakpoint at the throw of encoding error in iOS
  7. Look at the data variable

About

A Cordova project to reproduce utf-8 encoding bug in the cordova-file-plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages