* Collect chunks from a sync source into an array. * @param {Iterable } source * @param {number} [limit] * @returns {Uint8Array[]}
(source, limit)
| 89 | * @returns {Uint8Array[]} |
| 90 | */ |
| 91 | function collectSync(source, limit) { |
| 92 | // Normalize source via fromSync() - accepts strings, ArrayBuffers, protocols, etc. |
| 93 | const normalized = fromSync(source); |
| 94 | const chunks = []; |
| 95 | let totalBytes = 0; |
| 96 | |
| 97 | for (const batch of normalized) { |
| 98 | for (let i = 0; i < batch.length; i++) { |
| 99 | const chunk = batch[i]; |
| 100 | if (limit !== undefined) { |
| 101 | totalBytes += TypedArrayPrototypeGetByteLength(chunk); |
| 102 | if (totalBytes > limit) { |
| 103 | throw new ERR_OUT_OF_RANGE('totalBytes', `<= ${limit}`, totalBytes); |
| 104 | } |
| 105 | } |
| 106 | ArrayPrototypePush(chunks, chunk); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return chunks; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Collect chunks from an async or sync source into an array. |
no test coverage detected