Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. CompressionStream
  4. writable

CompressionStream: 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 theCompressionStream interface returns aWritableStream that accepts uncompressed data to be compressed, in the form ofArrayBuffer,TypedArray, orDataView chunks.

Value

AWritableStream.

Examples

This example creates aCompressionStream that performs gzip compression. It writes some binary data to thewritable stream, then reads the compressed data from thereadable stream.

js
const stream = new CompressionStream("gzip");// Write data to be compressedconst data = new TextEncoder().encode("Hello, world!");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 Uint8Array(output).toBase64()); // H4sIAAAAAAAAE/NIzcnJ11Eozy/KSVEEAObG5usNAAAA

Specifications

Specification
Streams
# dom-generictransformstream-writable

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp