What is hash-base?
The hash-base package is a Node.js module that provides a base implementation for creating hash functions. It is designed to be extended by other modules to create specific hash function implementations. The package simplifies the process of implementing hash algorithms by handling common tasks such as buffering and streaming data.
Streaming data through hash function
This code demonstrates how to extend the HashBase class to create a custom hash function. It involves defining the block size in the constructor, implementing the _update method to update the hash state, and the _digest method to produce the final hash output.
"use strict";
const HashBase = require('hash-base');
class MyHash extends HashBase {
constructor () {
super(64); // block size
}
_update () {
// update hash state with this._block
}
_digest () {
// return the final hash
return Buffer.from([]);
}
}
const hash = new MyHash();
hash.update('Hello, world!');
console.log(hash.digest('hex'));