* Normalize a sync streamable source, yielding batches of Uint8Array. * @param {Iterable} source * @yields {Uint8Array[]}
(source)
| 209 | * @yields {Uint8Array[]} |
| 210 | */ |
| 211 | function* normalizeSyncSource(source) { |
| 212 | let batch = []; |
| 213 | |
| 214 | for (const value of source) { |
| 215 | // Fast path 1: value is already a Uint8Array[] batch |
| 216 | if (isUint8ArrayBatch(value)) { |
| 217 | if (batch.length > 0) { |
| 218 | yield batch; |
| 219 | batch = []; |
| 220 | } |
| 221 | yield* yieldBoundedBatch(value); |
| 222 | continue; |
| 223 | } |
| 224 | // Fast path 2: value is a single Uint8Array (very common) |
| 225 | if (isUint8Array(value)) { |
| 226 | ArrayPrototypePush(batch, value); |
| 227 | if (batch.length === FROM_BATCH_SIZE) { |
| 228 | yield batch; |
| 229 | batch = []; |
| 230 | } |
| 231 | continue; |
| 232 | } |
| 233 | // Slow path: normalize the value |
| 234 | if (batch.length > 0) { |
| 235 | yield batch; |
| 236 | batch = []; |
| 237 | } |
| 238 | let valueBatch = []; |
| 239 | for (const chunk of normalizeSyncValue(value)) { |
| 240 | ArrayPrototypePush(valueBatch, chunk); |
| 241 | if (valueBatch.length === FROM_BATCH_SIZE) { |
| 242 | yield valueBatch; |
| 243 | valueBatch = []; |
| 244 | } |
| 245 | } |
| 246 | if (valueBatch.length > 0) { |
| 247 | yield valueBatch; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | if (batch.length > 0) { |
| 252 | yield batch; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // ============================================================================= |
| 257 | // Async Normalization (for from and async contexts) |
no test coverage detected
searching dependent graphs…