MCPcopy Create free account
hub / github.com/WinterTC55/iter-streams / array

Function array

src/consumers.js:394–542  ·  view source on GitHub ↗

* Collect all chunks as an array from an async or sync source. * * @param source - Iterable or async iterable yielding Uint8Array[] batches * @param options - Optional signal and limit * @returns Promise resolving to array of Uint8Array chunks

(source, options)

Source from the content-addressed store, hash-verified

392 * @returns Promise resolving to array of Uint8Array chunks
393 */
394function array(source, options) {
395 return __awaiter(this, void 0, void 0, function () {
396 var signal, limit, chunks, batch, _i, batch_7, chunk, e_3_1, _a, source_7, batch, _b, batch_8, chunk, totalBytes, batch, _c, batch_9, chunk, e_4_1, _d, source_8, batch, _e, batch_10, chunk;
397 var _f, source_9, source_9_1, _g, source_10, source_10_1;
398 var _h, e_3, _j, _k, _l, e_4, _m, _o;
399 var _p, _q, _r;
400 return __generator(this, function (_s) {
401 switch (_s.label) {
402 case 0:
403 signal = options === null || options === void 0 ? void 0 : options.signal;
404 limit = options === null || options === void 0 ? void 0 : options.limit;
405 // Check for abort
406 if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
407 throw (_p = signal.reason) !== null && _p !== void 0 ? _p : new DOMException('Aborted', 'AbortError');
408 }
409 chunks = [];
410 if (!(!signal && limit === undefined)) return [3 /*break*/, 15];
411 if (!(0, from_js_1.isAsyncIterable)(source)) return [3 /*break*/, 13];
412 _s.label = 1;
413 case 1:
414 _s.trys.push([1, 6, 7, 12]);
415 _f = true, source_9 = __asyncValues(source);
416 _s.label = 2;
417 case 2: return [4 /*yield*/, source_9.next()];
418 case 3:
419 if (!(source_9_1 = _s.sent(), _h = source_9_1.done, !_h)) return [3 /*break*/, 5];
420 _k = source_9_1.value;
421 _f = false;
422 batch = _k;
423 for (_i = 0, batch_7 = batch; _i < batch_7.length; _i++) {
424 chunk = batch_7[_i];
425 chunks.push(chunk);
426 }
427 _s.label = 4;
428 case 4:
429 _f = true;
430 return [3 /*break*/, 2];
431 case 5: return [3 /*break*/, 12];
432 case 6:
433 e_3_1 = _s.sent();
434 e_3 = { error: e_3_1 };
435 return [3 /*break*/, 12];
436 case 7:
437 _s.trys.push([7, , 10, 11]);
438 if (!(!_f && !_h && (_j = source_9.return))) return [3 /*break*/, 9];
439 return [4 /*yield*/, _j.call(source_9)];
440 case 8:
441 _s.sent();
442 _s.label = 9;
443 case 9: return [3 /*break*/, 11];
444 case 10:
445 if (e_3) throw e_3.error;
446 return [7 /*endfinally*/];
447 case 11: return [7 /*endfinally*/];
448 case 12: return [3 /*break*/, 14];
449 case 13:
450 if ((0, from_js_1.isSyncIterable)(source)) {
451 for (_a = 0, source_7 = source; _a < source_7.length; _a++) {

Callers 1

consumers.test.tsFile · 0.90

Calls 2

pushMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected