Skip to content

Commit

Permalink
stream: pipeline accept Buffer as a valid first argument
Browse files Browse the repository at this point in the history
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 <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Linkgoron authored and targos committed Sep 4, 2021
1 parent fe28128 commit 6350213
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/internal/streams/utils.js
Expand Up @@ -6,11 +6,13 @@ const {
} = primordials;

function isReadable(obj) {
return !!(obj && typeof obj.pipe === 'function');
return !!(obj && typeof obj.pipe === 'function' &&
typeof obj.on === 'function');
}

function isWritable(obj) {
return !!(obj && typeof obj.write === 'function');
return !!(obj && typeof obj.write === 'function' &&
typeof obj.on === 'function');
}

function isStream(obj) {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-stream-pipeline.js
Expand Up @@ -1247,3 +1247,19 @@ const net = require('net');
() => common.mustNotCall(),
);
}

{
const content = 'abc';
pipeline(Buffer.from(content), PassThrough({ objectMode: true }),
common.mustSucceed(() => {}));

let res = '';
pipeline(Buffer.from(content), async function*(previous) {
for await (const val of previous) {
res += String.fromCharCode(val);
yield val;
}
}, common.mustSucceed(() => {
assert.strictEqual(res, content);
}));
}

0 comments on commit 6350213

Please sign in to comment.