Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a web app which does some processing on big text-files (> 500mb) via the FileReader API's readAsText() method.
It has been working great for years but suddenly I got empty responses: event.target.result is an empty string.

369MB works but 589MB does not work.

I have tested on multiple computers; same result, however it does work in Firefox. Chrome must have introduced this in a recent update.

Has this bug been submitted?

Is there any workaround?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
266 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is v8 limitation on String length.

Has this bug been submitted?

Here is the responsible commit: https://github.com/v8/v8/commit/ea56bf5513d0cbd2a35a9035c5c2996272b8b728

Running a bisect I felt on this Change-Log and found it was applied on Chrome v79.

Before this change the limit on 64-bits platforms was set to 1024MB, the new limit is 512MB, the half.

This means not only FileReader is affected, but any method that would try to produce such a big String.

Here is a simple example:

const header = 24;
const bytes = new Uint8Array( (512 * 1024 * 1024) - header );
let txt = new TextDecoder().decode( bytes );
console.log( txt.length ); // 536870888
txt += "f"; // RangeError

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...