Skip to content

Commit 9557dda

Browse files
Linkgoronruyadorno
authored andcommitted
stream: pipeline accept Buffer as a valid first argument
change isStream to also check existence of on, so it wont mistake buffers as Streams. fixes: #37731 PR-URL: #37739Fixes: #37731 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0f2e142 commit 9557dda

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

‎lib/internal/streams/utils.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ const{
66
}=primordials;
77

88
functionisReadable(obj){
9-
return!!(obj&&typeofobj.pipe==='function');
9+
return!!(obj&&typeofobj.pipe==='function'&&
10+
typeofobj.on==='function');
1011
}
1112

1213
functionisWritable(obj){
13-
return!!(obj&&typeofobj.write==='function');
14+
return!!(obj&&typeofobj.write==='function'&&
15+
typeofobj.on==='function');
1416
}
1517

1618
functionisStream(obj){

‎test/parallel/test-stream-pipeline.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,3 +1371,19 @@ const net = require('net');
13711371
assert.strictEqual(res,'123');
13721372
}));
13731373
}
1374+
1375+
{
1376+
constcontent='abc';
1377+
pipeline(Buffer.from(content),PassThrough({objectMode: true}),
1378+
common.mustSucceed(()=>{}));
1379+
1380+
letres='';
1381+
pipeline(Buffer.from(content),asyncfunction*(previous){
1382+
forawait(constvalofprevious){
1383+
res+=String.fromCharCode(val);
1384+
yieldval;
1385+
}
1386+
},common.mustSucceed(()=>{
1387+
assert.strictEqual(res,content);
1388+
}));
1389+
}

0 commit comments

Comments
(0)