MCPcopy
hub / github.com/webpack/webpack / readFile

Method readFile

lib/serialization/FileMiddleware.js:642–782  ·  lib/serialization/FileMiddleware.js::FileMiddleware.readFile
(name)

Source from the content-addressed store, hash-verified

640 * @returns {Promise<Buffer[]>} result
641 */
642 const readFile = (name) =>
643 new Promise((resolve, reject) => {
644 const file = name
645 ? join(this.fs, filename, `../${name}${extension}`)
646 : filename;
647 this.fs.stat(file, (err, stats) => {
648 if (err) {
649 reject(err);
650 return;
651 }
652 let remaining = /** @type {IStats} */ (stats).size;
653 /** @type {Buffer | undefined} */
654 let currentBuffer;
655 /** @type {number | undefined} */
656 let currentBufferUsed;
657 /** @type {Buffer[]} */
658 const buf = [];
659 /** @type {import(class="st">"zlib").Zlib & import(class="st">"stream").Transform | undefined} */
660 let decompression;
661 if (file.endsWith(class="st">".gz")) {
662 decompression = createGunzip({
663 chunkSize: DECOMPRESSION_CHUNK_SIZE
664 });
665 } else if (file.endsWith(class="st">".br")) {
666 decompression = createBrotliDecompress({
667 chunkSize: DECOMPRESSION_CHUNK_SIZE
668 });
669 }
670 if (decompression) {
671 /** @typedef {(value: Buffer[] | PromiseLike<Buffer[]>) => void} NewResolve */
672 /** @typedef {(reason?: Error) => void} NewReject */
673
674 /** @type {NewResolve | undefined} */
675 let newResolve;
676 /** @type {NewReject | undefined} */
677 let newReject;
678 resolve(
679 Promise.all([
680 new Promise((rs, rj) => {
681 newResolve = rs;
682 newReject = rj;
683 }),
684 new Promise(
685 /**
686 * Handles the chunk size callback for this hook.
687 * @param {(value?: undefined) => void} resolve resolve
688 * @param {(reason?: Error) => void} reject reject
689 */
690 (resolve, reject) => {
691 decompression.on(class="st">"data", (chunk) => buf.push(chunk));
692 decompression.on(class="st">"end", () => resolve());
693 decompression.on(class="st">"error", (err) => reject(err));
694 }
695 )
696 ]).then(() => buf)
697 );
698 resolve = /** @type {NewResolve} */ (newResolve);
699 reject = /** @type {NewReject} */ (newReject);

Callers 15

_readFileHashMethod · 0.80
_getManagedItemInfoMethod · 0.80
_loadFileMethod · 0.80
processExistingFileMethod · 0.80
_readRecordsMethod · 0.80
applyMethod · 0.80
applyMethod · 0.80
readJsonFunction · 0.80
readLockfileMethod · 0.80
applyMethod · 0.80
runWriteMethod · 0.80

Calls 4

joinFunction · 0.85
resolveFunction · 0.85
readFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected