MCPcopy Index your code
hub / github.com/nodejs/node / parsePipeToArgs

Function parsePipeToArgs

lib/internal/streams/iter/pull.js:90–130  ·  view source on GitHub ↗

* Parse pipeTo/pipeToSync arguments: [...transforms, writer, options?] * @param {Array} args * @param {string} requiredMethod - 'write' for pipeTo, 'writeSync' for pipeToSync * @returns {{ transforms: Array, writer: object, options: object }}

(args, requiredMethod)

Source from the content-addressed store, hash-verified

88 * @returns {{ transforms: Array, writer: object, options: object }}
89 */
90function parsePipeToArgs(args, requiredMethod) {
91 if (args.length === 0) {
92 throw new ERR_INVALID_ARG_VALUE('args', args, 'pipeTo requires a writer argument');
93 }
94
95 let options;
96 let writerIndex = args.length - 1;
97
98 // Check if last arg is options
99 const last = args[args.length - 1];
100 if (isPullOptions(last) && !hasMethod(last, requiredMethod)) {
101 options = last;
102 writerIndex = args.length - 2;
103 }
104
105 if (writerIndex < 0) {
106 throw new ERR_INVALID_ARG_VALUE('args', args, 'pipeTo requires a writer argument');
107 }
108
109 const writer = args[writerIndex];
110 if (!hasMethod(writer, requiredMethod)) {
111 throw new ERR_INVALID_ARG_TYPE(
112 'writer', `object with a ${requiredMethod} method`, writer);
113 }
114
115 const transforms = ArrayPrototypeSlice(args, 0, writerIndex);
116 for (let i = 0; i < transforms.length; i++) {
117 if (!isTransform(transforms[i])) {
118 throw new ERR_INVALID_ARG_TYPE(
119 `transforms[${i}]`, ['Function', 'Object with transform()'],
120 transforms[i]);
121 }
122 }
123
124 return {
125 __proto__: null,
126 transforms,
127 writer,
128 options,
129 };
130}
131
132function canUseSyncIterablePipeToFastPath(source, transforms, signal) {
133 if (signal !== undefined ||

Callers 2

pipeToSyncFunction · 0.85
pipeToFunction · 0.85

Calls 3

isPullOptionsFunction · 0.85
hasMethodFunction · 0.85
isTransformFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…