
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@mattiasbuelens/web-streams-adapter
Advanced tools
Adapters for converting between different implementations of WHATWG Streams
Adapters for converting between different implementations of WHATWG Streams.
When you've got a ReadableStream from a native web API, you might be disappointed to find out
that not all browser support the latest and greatest features from the streams spec yet:
const response = await fetch('http://example.com/data.txt');
const readable = response.body;
const writable = new WritableStream({ write(chunk) { console.log(chunk) } });
await readable.pipeTo(writable); // TypeError: Object doesn't support property or method 'pipeTo'
This is because although many browsers have already started implementing streams, most of them are not yet fully up-to-date with the latest specification:
ReadableStream, WritableStream and TransformStream.
Readable byte streams are supported as of Chrome 89.
However, async iteration is not yet supported.ReadableStream, but no readable byte streams or writable streams yet.
As such, methods like pipeTo() and pipeThrough() that take a WritableStream are not yet supported either.ReadableStream, but no readable byte streams or writable streams.For up-to-date information, check caniuse.com
and the browser compatibility tables on MDN for ReadableStream and WritableStream.
web-streams-adapter provides adapter functions that take any readable/writable/transform stream
and wraps it into a different readable/writable/stream with a different (more complete) implementation of your choice,
for example web-streams-polyfill.
// setup
import { ReadableStream as PolyfillReadableStream } from 'web-streams-polyfill';
import { createReadableStreamWrapper } from '@mattiasbuelens/web-streams-adapter';
const toPolyfillReadable = createReadableStreamWrapper(PolyfillReadableStream);
// when handling a fetch response
const response = await fetch('http://example.com/data.txt');
const readable = toPolyfillReadable(response.body);
console.log(readable instanceof PolyfillReadableStream); // -> true
await readable.pipeTo(writable); // works!
You can also use an adapter to convert from your polyfilled stream back to a native stream:
// setup
const toNativeReadable = createReadableStreamWrapper(self.ReadableStream);
// when starting a fetch with a streaming POST body
const readable = new PolyfillReadableStream({ /* amazingness */ });
const response = await fetch(url, {
method: 'POST',
body: toNativeReadable(readable) // works!
});
For readable streams, web-streams-adapter creates an underlying source that pulls from the given readable stream
using the primitive reader API. This source can then be used by any other readable stream implementation,
both native and polyfilled ones.
For writable and transform streams, it uses a very similar approach to create an underlying sink or transformer using primitive reader and writer APIs on the given stream.
FAQs
Adapters for converting between different implementations of WHATWG Streams
We found that @mattiasbuelens/web-streams-adapter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.