stream: use .chunk when calling adapters's writev

Fix: https://github.com/nodejs/node/issues/42157

PR-URL: https://github.com/nodejs/node/pull/42161
Fixes: https://github.com/nodejs/node/issues/42157
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Xuguang Mei authored and Stewart X Addison committed 2022-03-07 17:44:02 +00:00
1 parent 9aeda47d9c
commit 06e5c0ee39
3 files changed
+27 -5

No files matched your search

+6 -4
View File
@@ -228,8 +228,9 @@ function newStreamWritableFromWritableStream(writableStream, options = {}) {
writev(chunks, callback) {
function done(error) {
error = error.filter((e) => e);
try {
callback(error);
callback(error.length === 0 ? undefined : error);
} catch (error) {
// In a next tick because this is happening within
// a promise context, and if there are any errors
@@ -247,7 +248,7 @@ function newStreamWritableFromWritableStream(writableStream, options = {}) {
PromiseAll(
ArrayPrototypeMap(
chunks,
(chunk) => writer.write(chunk))),
(data) => writer.write(data.chunk))),
done,
done);
},
@@ -633,8 +634,9 @@ function newStreamDuplexFromReadableWritablePair(pair = {}, options = {}) {
writev(chunks, callback) {
function done(error) {
error = error.filter((e) => e);
try {
callback(error);
callback(error.length === 0 ? undefined : error);
} catch (error) {
// In a next tick because this is happening within
// a promise context, and if there are any errors
@@ -652,7 +654,7 @@ function newStreamDuplexFromReadableWritablePair(pair = {}, options = {}) {
PromiseAll(
ArrayPrototypeMap(
chunks,
(chunk) => writer.write(chunk))),
(data) => writer.write(data.chunk))),
done,
done);
},
@@ -147,3 +147,20 @@ const {
finished(duplex, common.mustCall());
pipeline(readable, duplex, writable, common.mustCall());
}
{
const transform = new TransformStream();
const duplex = newStreamDuplexFromReadableWritablePair(transform);
duplex.setEncoding('utf-8');
duplex.on('data', common.mustCall((data) => {
assert.strictEqual(data, 'hello');
}, 5));
duplex.write(Buffer.from('hello'));
duplex.write(Buffer.from('hello'));
duplex.write(Buffer.from('hello'));
duplex.write(Buffer.from('hello'));
duplex.write(Buffer.from('hello'));
duplex.end();
}
@@ -200,7 +200,7 @@ class TestSource {
{
const writableStream = new WritableStream({
write: common.mustCall(2),
write: common.mustCall(5),
close: common.mustCall(),
});
const writable = newStreamWritableFromWritableStream(writableStream);
@@ -208,6 +208,9 @@ class TestSource {
finished(writable, common.mustCall());
writable.write('hello');
writable.write('hello');
writable.write('hello');
writable.write('world');
writable.write('world');
writable.end();
}