@@ -22,20 +22,23 @@ const {
2222 validateBoolean
2323} = require ( 'internal/validators' ) ;
2424
25- const { Promise } = primordials ;
25+ const { Promise, PromisePrototypeThen } = primordials ;
2626
2727const {
2828 isClosed,
2929 isReadable,
3030 isReadableNodeStream,
31+ isReadableStream,
3132 isReadableFinished,
3233 isReadableErrored,
3334 isWritable,
3435 isWritableNodeStream,
36+ isWritableStream,
3537 isWritableFinished,
3638 isWritableErrored,
3739 isNodeStream,
3840 willEmitClose : _willEmitClose ,
41+ kIsClosedPromise,
3942} = require ( 'internal/streams/utils' ) ;
4043
4144function isRequest ( stream ) {
@@ -58,14 +61,17 @@ function eos(stream, options, callback) {
5861
5962 callback = once ( callback ) ;
6063
61- const readable = options . readable ?? isReadableNodeStream ( stream ) ;
62- const writable = options . writable ?? isWritableNodeStream ( stream ) ;
64+ if ( isReadableStream ( stream ) || isWritableStream ( stream ) ) {
65+ return eosWeb ( stream , options , callback ) ;
66+ }
6367
6468 if ( ! isNodeStream ( stream ) ) {
65- // TODO: Webstreams.
66- throw new ERR_INVALID_ARG_TYPE ( 'stream' , 'Stream' , stream ) ;
69+ throw new ERR_INVALID_ARG_TYPE ( 'stream' , [ 'ReadableStream' , 'WritableStream' , 'Stream' ] , stream ) ;
6770 }
6871
72+ const readable = options . readable ?? isReadableNodeStream ( stream ) ;
73+ const writable = options . writable ?? isWritableNodeStream ( stream ) ;
74+
6975 const wState = stream . _writableState ;
7076 const rState = stream . _readableState ;
7177
@@ -255,6 +261,15 @@ function eos(stream, options, callback) {
255261 return cleanup ;
256262}
257263
264+ function eosWeb ( stream , opts , callback ) {
265+ PromisePrototypeThen (
266+ stream [ kIsClosedPromise ] . promise ,
267+ ( ) => process . nextTick ( ( ) => callback . call ( stream ) ) ,
268+ ( err ) => process . nextTick ( ( ) => callback . call ( stream , err ) ) ,
269+ ) ;
270+ return nop ;
271+ }
272+
258273function finished ( stream , opts ) {
259274 let autoCleanup = false ;
260275 if ( opts === null ) {
0 commit comments