Skip to content

Commit 9b87ab4

Browse files
Linkgoronjasnell
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 af03f44 commit 9b87ab4

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
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,3 +1337,19 @@ const net = require('net');
13371337
assert.strictEqual(res, '123');
13381338
}));
13391339
}
1340+
1341+
{
1342+
const content = 'abc';
1343+
pipeline(Buffer.from(content), PassThrough({ objectMode: true }),
1344+
common.mustSucceed(() => {}));
1345+
1346+
let res = '';
1347+
pipeline(Buffer.from(content), async function*(previous) {
1348+
for await (const val of previous) {
1349+
res += String.fromCharCode(val);
1350+
yield val;
1351+
}
1352+
}, common.mustSucceed(() => {
1353+
assert.strictEqual(res, content);
1354+
}));
1355+
}

0 commit comments

Comments
 (0)