Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Blob: byte size and streaming reads

Blob holds immutable binary data. The Blob.size property reports its size in bytes, while Blob.stream() exposes the data for asynchronous, chunk-by-chunk reading through a ReadableStream.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

new Blob(blobParts, options)
blob.size
blob.stream()

Blob is an object holding immutable, raw data. The new Blob(blobParts, options) constructor combines the supplied parts into one object. File inherits Blob functionality but adds file-related information.

Blob.size names the instance property accessed as blob.size, without parentheses. It is read-only and returns the number of data bytes, not the number of text characters. Obtaining the size does not require asynchronously reading the contents.

Blob.stream names the instance method called as blob.stream(), without arguments. It returns a ReadableStream, not a promise for the entire contents. A reader obtained through getReader() lets you retrieve byte chunks asynchronously. The example sums their byteLength until done is true; it assumes no particular chunk count or size. Streaming does not change the Blob data.

These are Web API interfaces, not features assigned to an ECMAScript edition. MDN reports broad availability for Blob.size since July 2015 and Blob.stream() since April 2021. Both are also available in Web Workers. Check target-browser support separately; Node 24 in a repository does not establish that support.

Examples

async function main() {
  const blob = new Blob([new Uint8Array([65, 66, 67])]);
  const reader = blob.stream().getReader();
  let total = 0;

  try {
    while (true) {
      const { value, done } = await reader.read();
      if (done) break;
      total += value.byteLength;
    }
  } finally {
    reader.releaseLock();
  }

  console.log(`size=${blob.size}`);
  console.log(`read=${total}`);
  console.log(`match=${total === blob.size}`);
}

main().catch(console.error);

Result

size=3
read=3
match=true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources