| | |
| | | "use strict"; |
| | | |
| | | const Hash = require("../Hash"); |
| | | const { digest, update } = require("./hash-digest"); |
| | | /** @type {number} */ |
| | | const MAX_SHORT_STRING = require("./wasm-hash").MAX_SHORT_STRING; |
| | | |
| | | /** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */ |
| | | |
| | | class BatchedHash extends Hash { |
| | | /** |
| | | * Creates an instance of BatchedHash. |
| | | * @param {Hash} hash hash |
| | | */ |
| | | constructor(hash) { |
| | | super(); |
| | | /** @type {undefined | string} */ |
| | | this.string = undefined; |
| | | /** @type {undefined | Encoding} */ |
| | | this.encoding = undefined; |
| | | /** @type {Hash} */ |
| | | this.hash = hash; |
| | | } |
| | | |
| | |
| | | return this; |
| | | } |
| | | if (this.encoding) { |
| | | this.hash.update(this.string, this.encoding); |
| | | update(this.hash, this.string, this.encoding); |
| | | } else { |
| | | this.hash.update(this.string); |
| | | update(this.hash, this.string); |
| | | } |
| | | this.string = undefined; |
| | | } |
| | |
| | | this.string = data; |
| | | this.encoding = inputEncoding; |
| | | } else if (inputEncoding) { |
| | | this.hash.update(data, inputEncoding); |
| | | update(this.hash, data, inputEncoding); |
| | | } else { |
| | | this.hash.update(data); |
| | | update(this.hash, data); |
| | | } |
| | | } else { |
| | | this.hash.update(data); |
| | | update(this.hash, data); |
| | | } |
| | | return this; |
| | | } |
| | |
| | | digest(encoding) { |
| | | if (this.string !== undefined) { |
| | | if (this.encoding) { |
| | | this.hash.update(this.string, this.encoding); |
| | | update(this.hash, this.string, this.encoding); |
| | | } else { |
| | | this.hash.update(this.string); |
| | | update(this.hash, this.string); |
| | | } |
| | | } |
| | | if (!encoding) { |
| | | return this.hash.digest(); |
| | | return digest(this.hash); |
| | | } |
| | | return this.hash.digest(encoding); |
| | | return digest(this.hash, encoding); |
| | | } |
| | | } |
| | | |