blob
The Blob class represents immutable raw binary data. Blobs are commonly used for file-like objects, uploads, and binary manipulation.
API Surface
Class: Blob
new Blob(sources[, options])— create blob from array of parts.- Parts: strings, BufferSource, Blob.
- Options:
{ type: "mime/type" }.
Properties
blob.size— size in bytes.blob.type— MIME type string.
Methods
blob.slice([start], [end], [type])— return a new Blob view.blob.arrayBuffer()— resolve to ArrayBuffer.blob.text()— resolve to string.blob.stream()— readable stream of blob data.
Examples (English only)
// Create a blob from text
const b = new Blob(["Hello Bnlang"], { type: "text/plain" });
console.log("size:", b.size, "type:", b.type);
// Convert to text
const txt = await b.text();
console.log("text:", txt);
// Slice & arrayBuffer
const part = b.slice(0, 5, "text/plain");
console.log("part text:", await part.text());
// Stream blob
for await (const chunk of b.stream()) {
console.log("chunk:", chunk);
}
Notes
- Blobs are immutable; operations return new Blobs.
- MIME type is advisory; consumers may ignore it.
- Use
Blobwith FormData for file uploads. - For random access binary edits, use Buffer instead.