TransformStream is now supported cross-browser

The Streams API allows you to break down a resource that you want to receive, send, or transform into small chunks, and then process these chunks bit by bit. Recently, Firefox 102
started to support TransformStream,
which means TransformStream is now
f…


This content originally appeared on web.dev and was authored by Google Developers

The Streams API allows you to break down a resource that you want to receive, send, or transform into small chunks, and then process these chunks bit by bit. Recently, Firefox 102 started to support TransformStream, which means TransformStream is now finally usable across browsers. Transform streams allow you to pipe from a ReadableStream to a WritableStream, executing a transformation on the chunks, or consume the transformed result directly, as shown in the following example.

class UpperCaseTransformStream {
constructor() {
return new TransformStream({
transform(chunk, controller) {
controller.enqueue(chunk.toUpperCase());
},
});
}
}

button.addEventListener('click', async () => {
const response = await fetch('/script.js');
const readableStream = response.body
.pipeThrough(new TextDecoderStream())
.pipeThrough(new UpperCaseTransformStream());

const reader = readableStream.getReader();
pre.textContent = '';
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
pre.textContent += value;
}
});

Demo #

Browser support #

Browser support: chrome 67, Supported 67 firefox 102, Supported 102 edge 79, Supported 79 safari 14.1, Supported 14.1 Source

Acknowledgements #

Hero image by Arseny Togulev on Unsplash


This content originally appeared on web.dev and was authored by Google Developers


Print Share Comment Cite Upload Translate Updates
APA

Google Developers | Sciencx (2022-07-01T00:00:00+00:00) TransformStream is now supported cross-browser. Retrieved from https://www.scien.cx/2022/07/01/transformstream-is-now-supported-cross-browser/

MLA
" » TransformStream is now supported cross-browser." Google Developers | Sciencx - Friday July 1, 2022, https://www.scien.cx/2022/07/01/transformstream-is-now-supported-cross-browser/
HARVARD
Google Developers | Sciencx Friday July 1, 2022 » TransformStream is now supported cross-browser., viewed ,<https://www.scien.cx/2022/07/01/transformstream-is-now-supported-cross-browser/>
VANCOUVER
Google Developers | Sciencx - » TransformStream is now supported cross-browser. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/01/transformstream-is-now-supported-cross-browser/
CHICAGO
" » TransformStream is now supported cross-browser." Google Developers | Sciencx - Accessed . https://www.scien.cx/2022/07/01/transformstream-is-now-supported-cross-browser/
IEEE
" » TransformStream is now supported cross-browser." Google Developers | Sciencx [Online]. Available: https://www.scien.cx/2022/07/01/transformstream-is-now-supported-cross-browser/. [Accessed: ]
rf:citation
» TransformStream is now supported cross-browser | Google Developers | Sciencx | https://www.scien.cx/2022/07/01/transformstream-is-now-supported-cross-browser/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.