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

Function pipeToSync

src/pull.js:1189–1234  ·  view source on GitHub ↗

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

(source)

Source from the content-addressed store, hash-verified

1187 * @returns Total bytes written
1188 */
1189function pipeToSync(source) {
1190 var _a;
1191 var args = [];
1192 for (var _i = 1; _i < arguments.length; _i++) {
1193 args[_i - 1] = arguments[_i];
1194 }
1195 var _b = parsePipeToArgs(args), transforms = _b.transforms, writer = _b.writer, options = _b.options;
1196 // Handle transform-writer: if writer has transform, apply it as last transform
1197 var finalTransforms = __spreadArray([], transforms, true);
1198 if (isTransformObject(writer)) {
1199 finalTransforms.push(writer);
1200 }
1201 // Create pipeline
1202 var pipeline = finalTransforms.length > 0
1203 ? createSyncPipeline((_a = {}, _a[Symbol.iterator] = function () { return source[Symbol.iterator](); }, _a), finalTransforms)
1204 : source;
1205 var totalBytes = 0;
1206 try {
1207 for (var _c = 0, pipeline_1 = pipeline; _c < pipeline_1.length; _c++) {
1208 var batch = pipeline_1[_c];
1209 for (var _d = 0, batch_1 = batch; _d < batch_1.length; _d++) {
1210 var chunk = batch_1[_d];
1211 totalBytes += chunk.byteLength;
1212 }
1213 if ('writev' in writer && typeof writer.writev === 'function') {
1214 writer.writev(batch);
1215 }
1216 else {
1217 for (var _e = 0, batch_2 = batch; _e < batch_2.length; _e++) {
1218 var chunk = batch_2[_e];
1219 writer.write(chunk);
1220 }
1221 }
1222 }
1223 if (!(options === null || options === void 0 ? void 0 : options.preventClose)) {
1224 writer.end();
1225 }
1226 }
1227 catch (error) {
1228 if (!(options === null || options === void 0 ? void 0 : options.preventFail)) {
1229 writer.fail(error);
1230 }
1231 throw error;
1232 }
1233 return totalBytes;
1234}
1235/**
1236 * Write an async source through transforms to a writer.
1237 *

Callers 1

pull.test.tsFile · 0.90

Calls 8

parsePipeToArgsFunction · 0.70
isTransformObjectFunction · 0.70
createSyncPipelineFunction · 0.70
pushMethod · 0.65
writevMethod · 0.65
writeMethod · 0.65
endMethod · 0.65
failMethod · 0.65

Tested by

no test coverage detected