web api instance property
TransformStream: writable property
Available in workers
The writable read-only property of the TransformStream interface returns the WritableStream instance controlled by this TransformStream. This stream accepts input data that will be transformed and emitted to the readable stream.
Value
Examples
This example creates a TransformStream that converts all input text to uppercase letters. It writes some text to the writable stream, then reads the transformed text from the readable stream.
const stream = new TransformStream({
transform(chunk, controller) {
controller.enqueue(chunk.toUpperCase());
},
});
// Write data to be transformed
const writer = stream.writable.getWriter();
writer.write("hello ");
writer.write("world");
writer.close();
// Read transformed data
const reader = stream.readable.getReader();
let done = false;
let output = "";
while (!done) {
const result = await reader.read();
if (result.value) {
output += result.value;
}
done = result.done;
}
console.log(output); // HELLO WORLD
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.