Where is blob data stored?

Ultimately, a web application can work with the large amounts of data provided by Blobs. Some of them were obtained using XHR (caching), others were created using new Blob(...) .

  • Now, if I read correctly, are Blobs supported by either disk or memory?
  • How is this taken? (And do browsers make the same rules?)
  • Are there ways to enforce or guarantee certain behavior?

My main concern is how to manage these blobs. My initial idea was to just store links. But it would be bad if throughout the life of the application large pieces of data were stored in memory.

+4
source share
1 answer

What I have discovered so far, looking at the source code of Firefox: ( I still need to get confirmation! )

Blob objects are instances of the nsDOMFile subclasses. The implementation is wise, there are few differences between Blob and file. They are either nsDOMFileFile , nsDOMMemoryFile , nsDOMTemporaryFileBlob , or nsDOMMultipartFile .

Mostly nsDOMMemoryFile places are used only:

  • In HTMLCanvasElement#toBlob .
  • In the camera API.
  • In the Media Recorder API.
  • In WebSockets, when binaryType is 'blob' .
  • In WebRTC data channels, when binaryType is 'blob' .

All other places use nsDOMFileFile or nsDOMTemporaryFileBlob and are thus supported by disk storage, with the exception of the new Blob constructor.

Beans created using the new Blob constructor are instances of nsDOMMultipartFile . This class actually wraps the blob set (from the other three types described above) and represents them as one.

When passing a string or ArrayBuffer, they are copied to the new nsDOMMemoryFile , and then attached to the set. When transferring an existing Blob of any type, it is added to the set as is. Thus, nsDOMMultipartFile can have mixed memory and memory.

+2
source

Source: https://habr.com/ru/post/1493054/


All Articles