Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

javascript - Chrome, FileReader API, event.target.result === ""

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

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

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...