MCPcopy
hub / github.com/webpack/webpack / _readFileHash

Method _readFileHash

lib/FileSystemInfo.js:3675–3705  ·  lib/FileSystemInfo.js::FileSystemInfo._readFileHash

* @private * @type {Processor<string, string>}

(path, callback)

Source from the content-addressed store, hash-verified

3673 * @type {Processor<string, string>}
3674 */
3675 _readFileHash(path, callback) {
3676 this.fs.readFile(path, (err, content) => {
3677 if (err) {
3678 if (err.code === class="st">"EISDIR") {
3679 this._fileHashes.set(path, class="st">"directory");
3680 return callback(null, class="st">"directory");
3681 }
3682 if (err.code === class="st">"ENOENT") {
3683 this._fileHashes.set(path, null);
3684 return callback(null, null);
3685 }
3686 if (err.code === class="st">"ERR_FS_FILE_TOO_LARGE") {
3687 /** @type {Logger} */
3688 (this.logger).warn(`Ignoring ${path} for hashing as it's very large`);
3689 this._fileHashes.set(path, class="st">"too large");
3690 return callback(null, class="st">"too large");
3691 }
3692 return callback(/** @type {WebpackError} */ (err));
3693 }
3694
3695 const hash = createHash(this._hashFunction);
3696
3697 hash.update(/** @type {string | Buffer} */ (content));
3698
3699 const digest = hash.digest(class="st">"hex");
3700
3701 this._fileHashes.set(path, digest);
3702
3703 callback(null, digest);
3704 });
3705 }
3706
3707 /**
3708 * Get file timestamp and hash.

Callers

nothing calls this directly

Calls 7

createHashFunction · 0.85
readFileMethod · 0.80
warnMethod · 0.80
callbackFunction · 0.50
setMethod · 0.45
updateMethod · 0.45
digestMethod · 0.45

Tested by

no test coverage detected