An xxhash binding for node.js.
- node.js -- v0.6.0 or newer
npm install xxhash
- Hash a file in one step:
var XXHash = require('xxhash'),
fs = require('fs');
var file = fs.readFileSync('somefile'),
result = XXHash.hash(file, 0xCAFEBABE);
- Hash a file in multiple steps:
var XXHash = require('xxhash'),
fs = require('fs');
var hasher = new XXHash(0xCAFEBABE);
fs.createReadStream('somefile')
.on('data', function(data) {
hasher.update(data);
})
.on('end', function() {
console.log('Hash value = ' + hasher.digest());
});
- Hash a file with a hash stream:
var HashStream = require('xxhash').Stream,
fs = require('fs');
var hasher = new HashStream(0xCAFEBABE);
fs.createReadStream('somefile')
.pipe(hasher)
.on('finish', function() {
console.log('Hash value = ' + hasher.read());
});
- hash(< Buffer >data, < integer >seed) - integer - Performs a single/one-time hash of
data
with the givenseed
. The resulting hash is returned.
- Stream - DuplexStream - A stream constructor that takes in the seed to use. Write data to the stream and when the stream ends, the hash value is available on the readable side as an integer.
-
(constructor)(< Integer >seed) - Create and return a new Hash instance that uses the given
seed
. -
update(< Buffer >data) - (void) - Update the hash using
data
. Note: the length ofdata
must be a positive signed integer (e.g. 0 to 2,147,483,647 bytes). -
digest() - integer - Completes the hashing and returns the resulting integer hash. Note: hash object can not be used after digest() method been called.