The pipeTo() method of the ReadableStream interface pipes the current ReadableStream to a given WritableStream and returns a Promise that fulfills when the piping process completes successfully, or rejects if any errors were encountered.
Piping a stream will generally lock it for the duration of the pipe, preventing other readers from locking it.
pipeTo(destination)
pipeTo(destination, options)
A Promise that resolves when the piping process has completed.
fetch("png-logo.png")
.then((response) => response.body)
.then((body) => body.pipeThrough(new PNGTransformStream()))
.then((rs) => rs.pipeTo(new FinalDestinationStream()));
The same example, but using await:
(async () => {
const response = await fetch("png-logo.png");
response.body
.pipeThrough(new PNGTransformStream())
.pipeTo(new FinalDestinationStream());
})();