Skip to content

Commit 44f0733

Browse files
committed
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
1 parent c2a792f commit 44f0733

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
@@ -1339,3 +1339,19 @@ const net = require('net');
13391339
assert.strictEqual(res, '123');
13401340
}));
13411341
}
1342+
1343+
{
1344+
const content = 'abc';
1345+
pipeline(Buffer.from(content), PassThrough({ objectMode: true }),
1346+
common.mustSucceed(() => {}));
1347+
1348+
let res = '';
1349+
pipeline(Buffer.from(content), async function*(previous) {
1350+
for await (const val of previous) {
1351+
res += String.fromCharCode(val);
1352+
yield val;
1353+
}
1354+
}, common.mustSucceed(() => {
1355+
assert.strictEqual(res, content);
1356+
}));
1357+
}

0 commit comments

Comments
 (0)