* Normalize a sync streamable yield value to Uint8Array chunks. * Recursively flattens arrays, iterables, and protocol conversions. * @yields {Uint8Array}
(value)
| 134 | * @yields {Uint8Array} |
| 135 | */ |
| 136 | function* normalizeSyncValue(value) { |
| 137 | // Handle primitives |
| 138 | if (isPrimitiveChunk(value)) { |
| 139 | yield primitiveToUint8Array(value); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | // Handle ToStreamable protocol |
| 144 | if (hasProtocol(value, toStreamable)) { |
| 145 | const result = FunctionPrototypeCall(value[toStreamable], value); |
| 146 | yield* normalizeSyncValue(result); |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | // Handle arrays (which are also iterable, but check first for efficiency) |
| 151 | if (ArrayIsArray(value)) { |
| 152 | for (let i = 0; i < value.length; i++) { |
| 153 | yield* normalizeSyncValue(value[i]); |
| 154 | } |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | // Handle other sync iterables |
| 159 | if (isSyncIterable(value)) { |
| 160 | for (const item of value) { |
| 161 | yield* normalizeSyncValue(item); |
| 162 | } |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | // Reject: no valid conversion |
| 167 | throw new ERR_INVALID_ARG_TYPE( |
| 168 | 'value', |
| 169 | ['string', 'ArrayBuffer', 'ArrayBufferView', 'Iterable', 'toStreamable'], |
| 170 | value, |
| 171 | ); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Check if value is already a Uint8Array[] batch (fast path). |
no test coverage detected
searching dependent graphs…