Given
var data = new Array(1000000);
for (var i = 0; i < data.length; i++) {
data[i] = 1;
}
var blob = new Blob([data]);
where is binary data representation of array stored?
Given
var data = new Array(1000000);
for (var i = 0; i < data.length; i++) {
data[i] = 1;
}
var blob = new Blob([data]);
where is binary data representation of array stored?
Blob is stored in memory. In browser blob storage. If you create a blob object, you can check it at Firefox memory profiler(about:memory). An example of firefox output, here we can see, selected files. There is a difference between Blob and File. Blob stores at the memory, File stores at filesystem.
There is a bug in Google Chrome. Chrome has blob limit. When you create total blob amount more than 500mb. The browser will stop creating blobs, because of blob storage is reached a 500mb limit. The only way to avoid this is to write a blob to IndexDb and remove from IndexDb. When a blob is written to indexDb, blob object automatically will be saved to a file system (blob will be converted to file). Blobs will be cleaned from memory with Garbage Collector after you will stop using them, or make blob = null. But GC will remove blob after some time, not instantaneously.
This will not answer your question fully.
From official fileAPI documentation,
A
Blob
is stored in the memory much like any otherArrayBuffer
. It's stored in the ram, just like the other objects declared in the window.Looking at the
chrome://blob-internals
, we can see how its physically stored in the ram. Here is an example blob.On printing the actual contents of the blob, we get a normal js file.
All variables that are not explicitly represented in any other storage are stored in memory (RAM) and lives there till end of your program or while you unset it (clear it from memory).
TLDR; In RAM
Blobs represent a bunch of data that could live anywhere. The File API specification intentionally does not offer any synchronous way of reading a Blob's contents.
Here are some concrete possibilities.
Uint8Array
, the Blob's contents lives in memory, at least for a while.<input type="file">
, the Blob's contents lives on disk, in the file selected by the user. The spec mentions snapshotting, but no implementation does it, because it'd add a lot of lag to user operations.In Chrome, we use a multi-process architecture where the browser process has a central registry of all live Blobs, and serves as the source of truth for blob contents. When a Blob is created in a renderer (by JavaScript), its contents is moved to the browser process via IPC, shared memory, or temporary files, depending on the size of the Blob. The browser process may also evict in-memory Blob contents to temporary files. The 500mb limit mentioned in a previous answer was lifted around 2016. More implementation details are in the README for Chrome's Blobs subsystem.