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

lib: implement finished for webstreams #45898

Closed
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
25 changes: 20 additions & 5 deletions lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ const {
willEmitClose: _willEmitClose,
} = require('internal/streams/utils');

const Readable = require('internal/streams/readable');
const Writable = require('internal/streams/writable');

const {
isBrandCheck,
} = require('internal/webstreams/util');

const isReadableStream =
isBrandCheck('ReadableStream');
const isWritableStream =
isBrandCheck('WritableStream');

function isRequest(stream) {
return stream.setHeader && typeof stream.abort === 'function';
}
Expand All @@ -58,14 +70,17 @@ function eos(stream, options, callback) {

callback = once(callback);

const readable = options.readable ?? isReadableNodeStream(stream);
const writable = options.writable ?? isWritableNodeStream(stream);

if (!isNodeStream(stream)) {
// TODO: Webstreams.
throw new ERR_INVALID_ARG_TYPE('stream', 'Stream', stream);
if (isReadableStream(stream)) {
stream = Readable.fromWeb(stream);
} else if (isWritableStream(stream)) {
stream = Writable.fromWeb(stream);
}
}

const readable = options.readable ?? isReadableNodeStream(stream);
const writable = options.writable ?? isWritableNodeStream(stream);

const wState = stream._writableState;
const rState = stream._readableState;

Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-webstreams-finished.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const { ReadableStream, WritableStream } = require('stream/web');
const { finished } = require('stream');

{
const rs = new ReadableStream({
start(controller) {
controller.enqueue('asd');
},
});
finished(rs, common.mustCall(() => {

}));
}