Content-Length: 154134 | pFad | http://developer.mozilla.org/en-US/docs/Web/API/TextEncoderStream/writable

TextEncoderStream: writable property - Web APIs | MDN

TextEncoderStream: 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 September 2022.

Note: This feature is available in Web Workers.

The writable read-only property of the TextEncoderStream interface returns a WritableStream that accepts strings to be encoded into binary data.

Value

A WritableStream.

Examples

This example creates a TextEncoderStream that encodes strings as UTF-8. It writes some strings to the writable stream, then reads the encoded binary data from the readable stream.

js
const stream = new TextEncoderStream();

// Write data to be encoded
const data = "你好世界";
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()); // 5L2g5aW95LiW55WM

Specifications

Specification
Streams
# dom-generictransformstream-writable

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: http://developer.mozilla.org/en-US/docs/Web/API/TextEncoderStream/writable

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy