mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
Add support for the creation of ReadableByteStream to Readable.toWeb()
and Duplex.toWeb()
This enables the use of .getReader({ mode: "byob" }) on
e.g. socket().toWeb()
Refs: https://github.com/nodejs/node/issues/56004#issuecomment-2908265316
Refs: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_byte_streams
PR-URL: https://github.com/nodejs/node/pull/58664
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Mattias Buelens <mattias@buelens.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
16 lines
501 B
JavaScript
16 lines
501 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const { Readable } = require('stream');
|
|
const assert = require('assert');
|
|
const common = require('../common');
|
|
{
|
|
const r = Readable.from([]);
|
|
// Cancelling reader while closing should not cause uncaught exceptions
|
|
r.on('close', common.mustCall(() => reader.cancel()));
|
|
|
|
const reader = Readable.toWeb(r, { type: 'bytes' }).getReader({ mode: 'byob' });
|
|
reader.read(new Uint8Array(16)).then(common.mustCall((result) => {
|
|
assert.ok(result.done);
|
|
}));
|
|
}
|