function digestHash(algo: string, data: ArrayBuffer | string, encoding?: HexBase64Latin1Encoding) { let h: Hash h = createHash(algo.replace("-", "")) h.update(typeof data === "string" ? data : Buffer.from(data)) if (!encoding) { return transferInto(h.digest()) } return h.digest(encoding) }
_read (size: number = 0) { let data = randBuffer(2048) if (this.totalSize - this.readBytes < data.length) { data = data.slice(0, this.totalSize - this.readBytes) } if (data.length > 0) { this.sha256.update(data) this.push(data) this.readBytes += data.length } if (this.readBytes >= this.totalSize) { this.sum = this.sha256.digest('hex') this.push(null) } }