MCPcopy Create free account
hub / github.com/nodejs/node / collectSync

Function collectSync

lib/internal/streams/iter/consumers.js:91–111  ·  view source on GitHub ↗

* Collect chunks from a sync source into an array. * @param {Iterable } source * @param {number} [limit] * @returns {Uint8Array[]}

(source, limit)

Source from the content-addressed store, hash-verified

89 * @returns {Uint8Array[]}
90 */
91function collectSync(source, limit) {
92 // Normalize source via fromSync() - accepts strings, ArrayBuffers, protocols, etc.
93 const normalized = fromSync(source);
94 const chunks = [];
95 let totalBytes = 0;
96
97 for (const batch of normalized) {
98 for (let i = 0; i < batch.length; i++) {
99 const chunk = batch[i];
100 if (limit !== undefined) {
101 totalBytes += TypedArrayPrototypeGetByteLength(chunk);
102 if (totalBytes > limit) {
103 throw new ERR_OUT_OF_RANGE('totalBytes', `<= ${limit}`, totalBytes);
104 }
105 }
106 ArrayPrototypePush(chunks, chunk);
107 }
108 }
109
110 return chunks;
111}
112
113/**
114 * Collect chunks from an async or sync source into an array.

Callers 4

bytesSyncFunction · 0.85
textSyncFunction · 0.85
arrayBufferSyncFunction · 0.85
arraySyncFunction · 0.85

Calls 1

fromSyncFunction · 0.70

Tested by

no test coverage detected