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
  • Loading branch information
Linkgoron committed Mar 16, 2021
1 parent c2a792f commit 44f0733
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 @@ -1339,3 +1339,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 44f0733

Please sign in to comment.