apache / apache/cordova-plugin-file

Android: Large file read error

Open
#238 6 comments 1 reaction 0 assignees View on GitHub
bug platform: android
Dominant language
JavaScript
Stars
744
Forks
754
Avg merge
3d 4h
Merged PRs (30d)
1

Description

When you read file by somethig like
```
var reader = new FileReader();
reader.onloadend=console.log;
reader.readAsText(file);
```
and if the file is bigger that CHUNK_SIZE (256kB) it gives you corrupted file: for example reading file that has about 0.5MB i get string, which length is over 800 000 characters (tested on android).

My solution, in **www/FileReader.js** instead of line
`readSuccessCallback.bind(this, readType, encoding, offset, totalSize, accumulate),`
put
`readSuccessCallback.bind(this, readType, encoding, offset, Math.min(totalSize - this._progress, CHUNK_SIZE), accumulate),`

Contributor guide

Open the contributing guide

Research direction

Start in www/FileReader.js at the readSuccessCallback.bind call, then reproduce the issue on Android with FileReader.readAsText and a file larger than CHUNK_SIZE. Verify that a roughly 0.5MB file is returned without corruption and that smaller files still behave correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, javascript
Domain
mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.