MCPcopy
hub / github.com/webpack/webpack / read

Method read

lib/serialization/BinaryMiddleware.js:230–253  ·  view source on GitHub ↗

* Returns buffer with bytes. * @param {number} n amount of bytes to read * @returns {Buffer} buffer with bytes

(n)

Source from the content-addressed store, hash-verified

228 * @returns {Buffer} buffer with bytes
229 */
230 read(n) {
231 this.ensureBuffer();
232 const rem =
233 /** @type {Buffer} */ (this.currentBuffer).length - this.currentPosition;
234 if (rem < n) {
235 const buffers = [this.read(rem)];
236 n -= rem;
237 this.ensureBuffer();
238 while (/** @type {Buffer} */ (this.currentBuffer).length < n) {
239 const b = /** @type {Buffer} */ (this.currentBuffer);
240 buffers.push(b);
241 n -= b.length;
242 this.nextDataItem();
243 this.ensureBuffer();
244 }
245 buffers.push(this.read(n));
246 return Buffer.concat(buffers);
247 }
248 const b = /** @type {Buffer} */ (this.currentBuffer);
249 const res = Buffer.from(b.buffer, b.byteOffset + this.currentPosition, n);
250 this.currentPosition += n;
251 this.checkOverflow();
252 return res;
253 }
254
255 /**
256 * Reads up to n bytes.

Callers 15

readU32Method · 0.95
deserializeMethod · 0.45
deserializeMethod · 0.45
deserializeMethod · 0.45
deserializeMethod · 0.45
deserializeMethod · 0.45
deserializeMethod · 0.45
deserializeMethod · 0.45
deserializeMethod · 0.45
deserializeMethod · 0.45
deserializeMethod · 0.45
deserializeMethod · 0.45

Calls 5

ensureBufferMethod · 0.95
nextDataItemMethod · 0.95
checkOverflowMethod · 0.95
pushMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected