Web APIs

TransformStream

Try the free JavaScript compiler

Creates a paired writable/readable stream with configurable transformation hooks.

Formal Syntax & Structure

javascript syntaxjavascript
new TransformStream(transformer)

Parameters & Attributes

NameTypeDescription
transformerobjectOptional transformation hooks.

Return Value

TransformStream

Creates a paired writable/readable stream with configurable transformation hooks.

Working Example

Example Snippetjavascript
(async () => {const src=new ReadableStream({start(c){c.enqueue(2);c.enqueue(3);c.close();}});const t=new TransformStream({transform(n,c){c.enqueue(n*2);}});const r=src.pipeThrough(t).getReader();const a=await r.read(),b=await r.read(),d=await r.read();r.releaseLock();console.log(a.value,b.value,d.done);})()
JavaScript Reference