MCPcopy
hub / github.com/webpack/webpack / ensureData

Function ensureData

lib/serialization/FileMiddleware.js:274–301  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

272 * @param {number} n number of bytes to ensure
273 */
274 const ensureData = (n) => {
275 if (contentPosition === contentItemLength) {
276 nextContent();
277 }
278 while (contentItemLength - contentPosition < n) {
279 const remaining = contentItem.subarray(contentPosition);
280 let lengthFromNext = n - remaining.length;
281 /** @type {Buffer[]} */
282 const buffers = [remaining];
283 for (let i = contentsIndex + 1; i < contents.length; i++) {
284 const l = contents[i].length;
285 if (l > lengthFromNext) {
286 buffers.push(contents[i].subarray(0, lengthFromNext));
287 contents[i] = contents[i].subarray(lengthFromNext);
288 lengthFromNext = 0;
289 break;
290 } else {
291 buffers.push(contents[i]);
292 contentsIndex = i;
293 lengthFromNext -= l;
294 }
295 }
296 if (lengthFromNext > 0) throw new Error("Unexpected end of data");
297 contentItem = Buffer.concat(buffers, n);
298 contentItemLength = n;
299 contentPosition = 0;
300 }
301 };
302 /**
303 * Returns value value.
304 * @returns {number} value value

Callers 3

readUInt32LEFunction · 0.85
readInt32LEFunction · 0.85
readSliceFunction · 0.85

Calls 3

nextContentFunction · 0.85
pushMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected