xxhash-nan
v0.9.0
Published
xxhash bindings for node.js, using nan for portability
Downloads
6
Maintainers
Readme
xxhash-nan
An xxhash binding for node.js. Forked from the original to add compatibility with future versions of node via NAN.
Installation
You must be running node 0.8 or later. (Thanks to an npm 2.0 compatibility issue, travis tests fail on 0.8.)
npm install xxhash
Examples
- Hash a file in one step:
var XXHash = require('xxhash-nan'),
fs = require('fs');
var file = fs.readFileSync('somefile'),
result = XXHash.hash(file, 0xCAFEBABE);
Hash a file incrementally:
var XXHash = require('xxhash-nan'),
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());
});
API
XXHash module functions
- hash(< Buffer >data, < integer >seed) - integer - Performs a single/one-time hash of
data
with the givenseed
. The resulting hash is returned.
XXHash Methods
(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.