简体   繁体   中英

In Javascript, when opening a file via an "input file" button, is the entire file read into memory

In javascript, when opening a file via a button returns a Blob object (eg blob1).
I can then get the actual data of the blob via blob1ArrayBuffer = blob1.arrayBuffer();

When the Blob object (eg blob1) is created, does it load all the bytes into memory?
Or does it just returns the address so that later the actual bytes can be read via blob1.arrayBuffer() ?

No, all the file isn't read in memory (you can try to open a file of a few TB, that should still work).
However note that the OS will still need to read some of that file to produce the metadata of the file. This may take some times in some conditions (eg when selecting folders with many files, or when selecting a file from a network disk etc.)

Even when doing blob1.arraybuffer() the full file isn't necessarily put in memory, since the specs ask that all the consumers of the Blob use a ReadableStream to get the data from it. But obviously in this case, the full data will be copied in the resulting ArrayBuffer that will most probably live in memory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM