LazyBlob
Summary
A lazy, streaming alternative to Blob.
Important: Since LazyBlob is not a Blob subclass, you cannot pass it directly to APIs
that expect a real Blob (like new Response(blob) or formData.append('file', blob)).
Instead, use one of:
.stream()- Returns aReadableStreamforResponseand other streaming APIs.toBlob()- Returns aPromise<Blob>for non-streaming APIs that require a completeBlob(e.g.FormData)
Signature
class LazyBlob {
constructor(
parts: LazyContent | BlobPartLike[],
options: LazyBlobOptions,
): LazyBlob;
// Accessors
get [toStringTag](): string;
get size(): number;
get type(): string;
// Methods
arrayBuffer(): Promise<ArrayBuffer>;
bytes(): Promise<Uint8Array<ArrayBuffer>>;
slice(start: number, end: number, contentType: string): LazyBlob;
stream(): ReadableStream<Uint8Array<ArrayBuffer>>;
text(): Promise<string>;
toBlob(): Promise<Blob>;
toString(): never;
}
Constructor Params
parts
The blob parts or lazy content
options
Options for the blob
Accessors
[toStringTag]
The brand string exposed by Object.prototype.toString.call().
size
The size of the blob in bytes.
type
The MIME type of the blob.
Methods
arrayBuffer(): Promise
Returns the blob's contents as an ArrayBuffer.
bytes(): Promise<Uint8Array>
Returns the blob's contents as a byte array.
slice(start: number, end: number, contentType: string): LazyBlob
Returns a new LazyBlob that contains the data in the specified range.
start
The start index (inclusive)
end
The end index (exclusive)
contentType
The content type of the new blob
stream(): ReadableStream<Uint8Array>
Returns a stream that can be used to read the blob's contents.
text(): Promise
Returns the blob's contents as a string.
toBlob(): Promise
Converts this LazyBlob to a native Blob.
Warning: This reads the entire content into memory, which defeats the purpose of using
a lazy blob for large files. Only use this for non-streaming APIs that require a complete Blob.
Use .stream() to get a ReadableStream for Response and other streaming APIs.