Skip to content

Commit 6350213

Browse files
Linkgorontargos
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 <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>
1 parent fe28128 commit 6350213

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/internal/streams/utils.js

+4-2
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

+16
Original file line numberDiff line numberDiff line change
@@ -1247,3 +1247,19 @@ const net = require('net');
12471247
() => common.mustNotCall(),
12481248
);
12491249
}
1250+
1251+
{
1252+
const content = 'abc';
1253+
pipeline(Buffer.from(content), PassThrough({ objectMode: true }),
1254+
common.mustSucceed(() => {}));
1255+
1256+
let res = '';
1257+
pipeline(Buffer.from(content), async function*(previous) {
1258+
for await (const val of previous) {
1259+
res += String.fromCharCode(val);
1260+
yield val;
1261+
}
1262+
}, common.mustSucceed(() => {
1263+
assert.strictEqual(res, content);
1264+
}));
1265+
}

0 commit comments

Comments
 (0)