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

Function pipeTo

src/pull.js:1242–1424  ·  view source on GitHub ↗

* Write an async source through transforms to a writer. * * @param source - The source yielding Uint8Array[] batches (sync or async) * @param args - Variadic transforms, writer (required), and optional options * @returns Promise resolving to total bytes written

(source)

Source from the content-addressed store, hash-verified

1240 * @returns Promise resolving to total bytes written
1241 */
1242function pipeTo(source) {
1243 var args = [];
1244 for (var _i = 1; _i < arguments.length; _i++) {
1245 args[_i - 1] = arguments[_i];
1246 }
1247 return __awaiter(this, void 0, void 0, function () {
1248 var _a, transforms, writer, options, finalTransforms, signal, totalBytes, hasWritev, writeBatch, batch, e_12_1, _b, _c, batch, streamableSource, pipeline, _d, pipeline_2, pipeline_2_1, batch, e_13_1, error_2;
1249 var _e, _f;
1250 var _this = this;
1251 var _g, source_6, source_6_1;
1252 var _h, e_12, _j, _k, _l, e_13, _m, _o;
1253 var _p, _q, _r, _s;
1254 return __generator(this, function (_t) {
1255 switch (_t.label) {
1256 case 0:
1257 _a = parsePipeToArgs(args), transforms = _a.transforms, writer = _a.writer, options = _a.options;
1258 finalTransforms = __spreadArray([], transforms, true);
1259 if (isTransformObject(writer)) {
1260 finalTransforms.push(writer);
1261 }
1262 signal = options === null || options === void 0 ? void 0 : options.signal;
1263 // Check for abort
1264 if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1265 throw (_p = signal.reason) !== null && _p !== void 0 ? _p : new DOMException('Aborted', 'AbortError');
1266 }
1267 totalBytes = 0;
1268 hasWritev = typeof writer.writev === 'function';
1269 writeBatch = function (batch) { return __awaiter(_this, void 0, void 0, function () {
1270 var _i, batch_3, chunk, promises, _a, batch_4, chunk, result;
1271 return __generator(this, function (_b) {
1272 switch (_b.label) {
1273 case 0:
1274 if (!(hasWritev && batch.length > 1)) return [3 /*break*/, 2];
1275 return [4 /*yield*/, writer.writev(batch, signal ? { signal: signal } : undefined)];
1276 case 1:
1277 _b.sent();
1278 for (_i = 0, batch_3 = batch; _i < batch_3.length; _i++) {
1279 chunk = batch_3[_i];
1280 totalBytes += chunk.byteLength;
1281 }
1282 return [3 /*break*/, 4];
1283 case 2:
1284 promises = [];
1285 for (_a = 0, batch_4 = batch; _a < batch_4.length; _a++) {
1286 chunk = batch_4[_a];
1287 result = writer.write(chunk, signal ? { signal: signal } : undefined);
1288 if (result !== undefined) {
1289 promises.push(result);
1290 }
1291 totalBytes += chunk.byteLength;
1292 }
1293 if (!(promises.length > 0)) return [3 /*break*/, 4];
1294 return [4 /*yield*/, Promise.all(promises)];
1295 case 3:
1296 _b.sent();
1297 _b.label = 4;
1298 case 4: return [2 /*return*/];
1299 }

Callers 1

pull.test.tsFile · 0.90

Calls 10

writeBatchFunction · 0.85
parsePipeToArgsFunction · 0.70
isTransformObjectFunction · 0.70
createAsyncPipelineFunction · 0.70
pushMethod · 0.65
writevMethod · 0.65
writeMethod · 0.65
endMethod · 0.65
failMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected