* Create a SyncByteStreamReadable from a ByteInput or SyncStreamable. * @param {string|ArrayBuffer|ArrayBufferView|Iterable} input * @returns {Iterable }
(input)
| 428 | * @returns {Iterable<Uint8Array[]>} |
| 429 | */ |
| 430 | function fromSync(input) { |
| 431 | if (input == null) { |
| 432 | throw new ERR_INVALID_ARG_TYPE('input', 'a non-null value', input); |
| 433 | } |
| 434 | |
| 435 | // Check for primitives first (ByteInput) |
| 436 | if (isPrimitiveChunk(input)) { |
| 437 | const chunk = primitiveToUint8Array(input); |
| 438 | return { |
| 439 | __proto__: null, |
| 440 | *[SymbolIterator]() { |
| 441 | yield [chunk]; |
| 442 | }, |
| 443 | }; |
| 444 | } |
| 445 | |
| 446 | // Fast path: Uint8Array[] - yield in bounded sub-batches. |
| 447 | // Yielding the entire array as one batch forces downstream transforms |
| 448 | // to process all data at once, causing peak memory proportional to total |
| 449 | // data volume. Sub-batching keeps peak memory bounded while preserving |
| 450 | // the throughput benefit of batched processing. |
| 451 | if (ArrayIsArray(input)) { |
| 452 | if (input.length === 0) { |
| 453 | return { |
| 454 | __proto__: null, |
| 455 | *[SymbolIterator]() { |
| 456 | // Empty - yield nothing |
| 457 | }, |
| 458 | }; |
| 459 | } |
| 460 | // Check if it's an array of Uint8Array (common case) |
| 461 | if (isUint8Array(input[0])) { |
| 462 | const allUint8 = ArrayPrototypeEvery(input, isUint8Array); |
| 463 | if (allUint8) { |
| 464 | const batch = input; |
| 465 | return { |
| 466 | __proto__: null, |
| 467 | *[SymbolIterator]() { |
| 468 | if (batch.length <= FROM_BATCH_SIZE) { |
| 469 | yield batch; |
| 470 | } else { |
| 471 | for (let i = 0; i < batch.length; i += FROM_BATCH_SIZE) { |
| 472 | yield ArrayPrototypeSlice(batch, i, i + FROM_BATCH_SIZE); |
| 473 | } |
| 474 | } |
| 475 | }, |
| 476 | }; |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | // Check toStreamable protocol (takes precedence over iteration protocols). |
| 482 | // toAsyncStreamable is ignored entirely in fromSync. |
| 483 | if (typeof input[toStreamable] === 'function') { |
| 484 | return fromSync(input[toStreamable]()); |
| 485 | } |
| 486 | |
| 487 | // Reject explicit async inputs |
no test coverage detected
searching dependent graphs…