MCPcopy
hub / github.com/webpack/webpack / deserialize

Method deserialize

lib/serialization/FileMiddleware.js:635–784  ·  view source on GitHub ↗

* Restores this instance from the provided deserializer context. * @param {SerializedType} data data * @param {Context} context context object * @returns {DeserializedType | Promise<DeserializedType>} deserialized data

(data, context)

Source from the content-addressed store, hash-verified

633 * @returns {DeserializedType | Promise<DeserializedType>} deserialized data
634 */
635 deserialize(data, context) {
636 const { filename, extension = "" } = context;
637 /**
638 * Returns result.
639 * @param {string | boolean} name name
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("zlib").Zlib & import("stream").Transform | undefined} */
660 let decompression;
661 if (file.endsWith(".gz")) {
662 decompression = createGunzip({
663 chunkSize: DECOMPRESSION_CHUNK_SIZE
664 });
665 } else if (file.endsWith(".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("data", (chunk) => buf.push(chunk));
692 decompression.on("end", () => resolve());

Callers

nothing calls this directly

Calls 1

deserializeFunction · 0.70

Tested by

no test coverage detected