Content-Length: 154162 | pFad | https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream/readable

CompressionStream: readable property - Web APIs | MDN

CompressionStream: readable property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2023.

Note: This feature is available in Web Workers.

The readable read-only property of the CompressionStream interface returns a ReadableStream that emits compressed data as Uint8Array chunks.

Value

A ReadableStream.

Examples

This example creates a CompressionStream that performs gzip compression. It writes some binary data to the writable stream, then reads the compressed data from the readable stream.

js
const stream = new CompressionStream("gzip");

// Write data to be compressed
const data = new TextEncoder().encode("Hello, world!");
const writer = stream.writable.getWriter();
writer.write(data);
writer.close();

// Read compressed data
const reader = stream.readable.getReader();
let done = false;
let output = [];
while (!done) {
  const result = await reader.read();
  if (result.value) {
    output.push(...result.value);
  }
  done = result.done;
}
console.log(new Uint8Array(output).toBase64()); // H4sIAAAAAAAAE/NIzcnJ11Eozy/KSVEEAObG5usNAAAA

Specifications

Specification
Streams
# dom-generictransformstream-readable

Browser compatibility

See also









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream/readable

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy