Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: make readable byte stream cloneable #46437

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ class ReadableStream {
this,
source,
extractHighWaterMark(highWaterMark, 0));
return;

// eslint-disable-next-line no-constructor-return
return makeTransferable(this);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this pattern is used right below this so I copied it from there, rather than separating onto separate lines.

// eslint-disable-next-line no-constructor-return
return makeTransferable(this);

}

if (type !== undefined)
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-webstream-byte-readable-clone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

require('../common');
const assert = require('assert');

{
// https://github.com/nodejs/node/issues/46296
const stream = new ReadableStream({
start(controller) {
controller.close();
},
type: 'bytes',
});

const clone = structuredClone(stream, { transfer: [stream] });

assert(clone instanceof ReadableStream);
}