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

Function normalizeSyncSource

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

* Normalize a sync streamable source, yielding batches of Uint8Array. * @param {Iterable} source * @yields {Uint8Array[]}

(source)

Source from the content-addressed store, hash-verified

209 * @yields {Uint8Array[]}
210 */
211function* normalizeSyncSource(source) {
212 let batch = [];
213
214 for (const value of source) {
215 // Fast path 1: value is already a Uint8Array[] batch
216 if (isUint8ArrayBatch(value)) {
217 if (batch.length > 0) {
218 yield batch;
219 batch = [];
220 }
221 yield* yieldBoundedBatch(value);
222 continue;
223 }
224 // Fast path 2: value is a single Uint8Array (very common)
225 if (isUint8Array(value)) {
226 ArrayPrototypePush(batch, value);
227 if (batch.length === FROM_BATCH_SIZE) {
228 yield batch;
229 batch = [];
230 }
231 continue;
232 }
233 // Slow path: normalize the value
234 if (batch.length > 0) {
235 yield batch;
236 batch = [];
237 }
238 let valueBatch = [];
239 for (const chunk of normalizeSyncValue(value)) {
240 ArrayPrototypePush(valueBatch, chunk);
241 if (valueBatch.length === FROM_BATCH_SIZE) {
242 yield valueBatch;
243 valueBatch = [];
244 }
245 }
246 if (valueBatch.length > 0) {
247 yield valueBatch;
248 }
249 }
250
251 if (batch.length > 0) {
252 yield batch;
253 }
254}
255
256// =============================================================================
257// Async Normalization (for from and async contexts)

Callers 1

[SymbolIterator]Function · 0.85

Calls 4

isUint8ArrayBatchFunction · 0.85
yieldBoundedBatchFunction · 0.85
isUint8ArrayFunction · 0.85
normalizeSyncValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…