Skip to content

Commit

Permalink
lib: implement finished for webstreams
Browse files Browse the repository at this point in the history
  • Loading branch information
debadree25 committed Jan 7, 2023
1 parent 513c151 commit d33cd07
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
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(() => {

}));
}

0 comments on commit d33cd07

Please sign in to comment.