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 ruyadorno committed Mar 24, 2021
1 parent 0f2e142 commit 9557dda
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1371,3 +1371,19 @@ const net = require('net');
assert.strictEqual(res, '123');
}));
}

{
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 9557dda

Please sign in to comment.