DecompressionStream: writable 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 inWeb Workers.
Thewritable read-only property of theDecompressionStream interface returns aWritableStream that accepts compressed data to be decompressed, in the form ofArrayBuffer,TypedArray, orDataView chunks.
In this article
Value
Examples
This example creates aDecompressionStream that performs gzip decompression. It writes some compressed binary data to thewritable stream, then reads the decompressed data from thereadable stream, decoding it as UTF-8 text.
js
const stream = new DecompressionStream("gzip");// Write data to be compressedconst data = Uint8Array.fromBase64( "H4sIAAAAAAAAE/NIzcnJ11Eozy/KSVEEAObG5usNAAAA",);const writer = stream.writable.getWriter();writer.write(data);writer.close();// Read compressed dataconst 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 TextDecoder().decode(new Uint8Array(output))); // Hello, world!Specifications
| Specification |
|---|
| Streams> # dom-generictransformstream-writable> |