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: #37739 Fixes: #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

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ const {
66
} = primordials;
77

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

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

1618
function isStream(obj) {

test/parallel/test-stream-pipeline.js

+16
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+
const content = 'abc';
1377+
pipeline(Buffer.from(content), PassThrough({ objectMode: true }),
1378+
common.mustSucceed(() => {}));
1379+
1380+
let res = '';
1381+
pipeline(Buffer.from(content), async function*(previous) {
1382+
for await (const val of previous) {
1383+
res += String.fromCharCode(val);
1384+
yield val;
1385+
}
1386+
}, common.mustSucceed(() => {
1387+
assert.strictEqual(res, content);
1388+
}));
1389+
}

0 commit comments

Comments
 (0)