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

Function normalizeSyncValue

lib/internal/streams/iter/from.js:136–172  ·  view source on GitHub ↗

* Normalize a sync streamable yield value to Uint8Array chunks. * Recursively flattens arrays, iterables, and protocol conversions. * @yields {Uint8Array}

(value)

Source from the content-addressed store, hash-verified

134 * @yields {Uint8Array}
135 */
136function* normalizeSyncValue(value) {
137 // Handle primitives
138 if (isPrimitiveChunk(value)) {
139 yield primitiveToUint8Array(value);
140 return;
141 }
142
143 // Handle ToStreamable protocol
144 if (hasProtocol(value, toStreamable)) {
145 const result = FunctionPrototypeCall(value[toStreamable], value);
146 yield* normalizeSyncValue(result);
147 return;
148 }
149
150 // Handle arrays (which are also iterable, but check first for efficiency)
151 if (ArrayIsArray(value)) {
152 for (let i = 0; i < value.length; i++) {
153 yield* normalizeSyncValue(value[i]);
154 }
155 return;
156 }
157
158 // Handle other sync iterables
159 if (isSyncIterable(value)) {
160 for (const item of value) {
161 yield* normalizeSyncValue(item);
162 }
163 return;
164 }
165
166 // Reject: no valid conversion
167 throw new ERR_INVALID_ARG_TYPE(
168 'value',
169 ['string', 'ArrayBuffer', 'ArrayBufferView', 'Iterable', 'toStreamable'],
170 value,
171 );
172}
173
174/**
175 * Check if value is already a Uint8Array[] batch (fast path).

Callers 1

normalizeSyncSourceFunction · 0.85

Calls 4

isPrimitiveChunkFunction · 0.85
primitiveToUint8ArrayFunction · 0.85
hasProtocolFunction · 0.85
isSyncIterableFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…