* Update hash https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding * @param {string | Buffer} data data * @param {Encoding=} inputEncoding data encoding * @returns {Hash} updated hash
(data, inputEncoding)
| 63 | * @returns {Hash} updated hash |
| 64 | */ |
| 65 | update(data, inputEncoding) { |
| 66 | if ( |
| 67 | inputEncoding !== undefined || |
| 68 | typeof data !== "string" || |
| 69 | data.length > BULK_SIZE |
| 70 | ) { |
| 71 | if (this.hash === undefined) { |
| 72 | this.hash = /** @type {HashFactory} */ (this.hashFactory)(); |
| 73 | } |
| 74 | if (this.buffer.length > 0) { |
| 75 | update(this.hash, this.buffer); |
| 76 | this.buffer = ""; |
| 77 | } |
| 78 | if (typeof data === "string" && inputEncoding) { |
| 79 | update(this.hash, data, inputEncoding); |
| 80 | } else { |
| 81 | update(this.hash, data); |
| 82 | } |
| 83 | } else { |
| 84 | this.buffer += data; |
| 85 | if (this.buffer.length > BULK_SIZE) { |
| 86 | if (this.hash === undefined) { |
| 87 | this.hash = /** @type {HashFactory} */ (this.hashFactory)(); |
| 88 | } |
| 89 | update(this.hash, this.buffer); |
| 90 | this.buffer = ""; |
| 91 | } |
| 92 | } |
| 93 | return this; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding} |