mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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: https://github.com/nodejs/node/issues/37731 PR-URL: https://github.com/nodejs/node/pull/37739 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
1 parent
0f2e142946
commit
9557dda2eb
2 files changed
+20
-2
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user