The blob object 1) is a data container for blob content
This is the API to work with binary data in the browser and is widely supported
Because any type of data is a blob, you can work with images, sound, and video inside the browser. Just upload any file and work with it as a Blob.
Once you have a Blob object, you can make it available offline by storing it within the browser.
You can use it in any fetch html element such as a, img, … with a ObjectUrl
Example for a plain text object where the type is the mime
let textBlob = new Blob(
["the text content for my bloc"],
{
type: 'text/plain'
}
);
Reading a blob is an async operation that can be done with several APIs.
With the en-US/docs/Web/API/Blob interface
(async () => {
let text = await textBlob.text();
console.log(`Result from Blob Interface ${text}`);
})();
With a en-US/docs/Web/API/FileReader and the load event
var reader = new FileReader();
reader.readAsText(textBlob);
reader.addEventListener("load", () => {
console.log(`Result from file reader ${reader.result}`);
}, false);
(async () => {
let text = await (new Response(textBlob)).text();
console.log(`Result from Response ${text}`);
})();