Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/internal/streams/iter/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,14 @@ function toUint8Array(chunk) {
}

/**
* Check if all chunks in an array are already Uint8Array (no strings).
* Short-circuits on the first string found.
* Check if all chunks in an array are already Uint8Array.
* Short-circuits on the first non-Uint8Array chunk found.
* @param {Array<Uint8Array|string>} chunks
* @returns {boolean}
*/
function allUint8Array(chunks) {
// Ok, well, kind of. This is more a check for "no strings"...
for (let i = 0; i < chunks.length; i++) {
if (typeof chunks[i] === 'string') return false;
if (!isUint8Array(chunks[i])) return false;
}
return true;
}
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-stream-iter-push-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,28 @@ async function testWritevSync() {
assert.strictEqual(result, 'hello');
}

async function testWritevSyncInvalidChunkDoesNotQueue() {
const { writer, readable } = push({ highWaterMark: 10 });

assert.throws(
() => writer.writevSync([1]),
{ code: 'ERR_INVALID_ARG_TYPE' },
);

const iter = readable[Symbol.asyncIterator]();
const next = iter.next();
const result = await Promise.race([
next.then(() => 'resolved'),
new Promise((resolve) => setImmediate(resolve, 'pending')),
]);
assert.strictEqual(result, 'pending');

writer.endSync();
const end = await next;
assert.strictEqual(end.value, undefined);
assert.strictEqual(end.done, true);
}

async function testWritevMixedTypes() {
const { writer, readable } = push({ highWaterMark: 10 });
// Mix strings and Uint8Arrays
Expand Down Expand Up @@ -494,6 +516,7 @@ Promise.all([
testOndrainRejectsOnConsumerThrow(),
testWritev(),
testWritevSync(),
testWritevSyncInvalidChunkDoesNotQueue(),
testWritevMixedTypes(),
testWriteAfterEnd(),
testWriteAfterFail(),
Expand Down
Loading