| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b57350f commit a5e7d89
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -190,15 +190,14 @@ function toUint8Array(chunk) { | |||
| 190 | 190 | } | |
| 191 | 191 | ||
| 192 | 192 | /** | |
| 193 | - * Check if all chunks in an array are already Uint8Array (no strings). | ||
| 194 | - * Short-circuits on the first string found. | ||
| 193 | + * Check if all chunks in an array are already Uint8Array. | ||
| 194 | + * Short-circuits on the first non-Uint8Array chunk found. | ||
| 195 | 195 | * @param {Array<Uint8Array|string>} chunks | |
| 196 | 196 | * @returns {boolean} | |
| 197 | 197 | */ | |
| 198 | 198 | function allUint8Array(chunks) { | |
| 199 | - // Ok, well, kind of. This is more a check for "no strings"... | ||
| 200 | 199 | for (let i = 0; i < chunks.length; i++) { | |
| 201 | - if (typeof chunks[i] === 'string') return false; | ||
| 200 | + if (!isUint8Array(chunks[i])) return false; | ||
| 202 | 201 | } | |
| 203 | 202 | return true; | |
| 204 | 203 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,6 +171,28 @@ async function testWritevSync() { | |||
| 171 | 171 | assert.strictEqual(result, 'hello'); | |
| 172 | 172 | } | |
| 173 | 173 | ||
| 174 | + async function testWritevSyncInvalidChunkDoesNotQueue() { | ||
| 175 | + const { writer, readable } = push({ highWaterMark: 10 }); | ||
| 176 | + | ||
| 177 | + assert.throws( | ||
| 178 | + () => writer.writevSync([1]), | ||
| 179 | + { code: 'ERR_INVALID_ARG_TYPE' }, | ||
| 180 | + ); | ||
| 181 | + | ||
| 182 | + const iter = readable[Symbol.asyncIterator](); | ||
| 183 | + const next = iter.next(); | ||
| 184 | + const result = await Promise.race([ | ||
| 185 | + next.then(() => 'resolved'), | ||
| 186 | + new Promise((resolve) => setImmediate(resolve, 'pending')), | ||
| 187 | + ]); | ||
| 188 | + assert.strictEqual(result, 'pending'); | ||
| 189 | + | ||
| 190 | + writer.endSync(); | ||
| 191 | + const end = await next; | ||
| 192 | + assert.strictEqual(end.value, undefined); | ||
| 193 | + assert.strictEqual(end.done, true); | ||
| 194 | + } | ||
| 195 | + | ||
| 174 | 196 | async function testWritevMixedTypes() { | |
| 175 | 197 | const { writer, readable } = push({ highWaterMark: 10 }); | |
| 176 | 198 | // Mix strings and Uint8Arrays | |
@@ -494,6 +516,7 @@ Promise.all([ | |||
| 494 | 516 | testOndrainRejectsOnConsumerThrow(), | |
| 495 | 517 | testWritev(), | |
| 496 | 518 | testWritevSync(), | |
| 519 | + testWritevSyncInvalidChunkDoesNotQueue(), | ||
| 497 | 520 | testWritevMixedTypes(), | |
| 498 | 521 | testWriteAfterEnd(), | |
| 499 | 522 | testWriteAfterFail(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments