Package Exports
- xxhash
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (xxhash) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Description
An xxhash binding for node.js.
Requirements
- node.js -- v4.0.0 or newer
Install
npm install xxhash
Examples
- Hash a file in one step:
var XXHash = require('xxhash');
var fs = require('fs');
var file = fs.readFileSync('somefile');
var result = XXHash.hash(file, 0xCAFEBABE);
- Hash a file in multiple steps:
var XXHash = require('xxhash');
var 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;
var fs = require('fs');
var hasher = new HashStream(0xCAFEBABE);
fs.createReadStream('somefile')
.pipe(hasher)
.on('finish', function() {
console.log('Hash value = ' + hasher.read());
});
API
XXHash Static Methods
hash(< _Buffer_ >data, < _mixed_ >seed[, < _mixed_ >encbuf]) - mixed - Performs a single/one-time 32-bit hash of
data
with the givenseed
.seed
can be an unsigned integer or a Buffer containing (1 <= n <= 4) bytes to use for the seed. The resulting hash is returned. The format of the hash depends on the value ofencbuf
. Ifencbuf
is a string and one of:buffer
,hex
,base64
, orbinary
, then the hash value will be encoded in the appropriate format. Ifencbuf
is a Buffer of at least 4 bytes, then the hash value will be written toencbuf
andencbuf
will be returned. Otherwise, ifencbuf
is not supplied, then the hash will be an unsigned integer.hash64(< _Buffer_ >data, < _mixed_ >seed[, < _mixed_ >encbuf]) - mixed - Performs a single/one-time 64-bit hash of
data
with the givenseed
.seed
can be an unsigned integer or a Buffer containing (1 <= n <= 8) bytes to use for the seed. The resulting hash is returned. The format of the hash depends on the value ofencbuf
. Ifencbuf
is a string and one of:buffer
,hex
,base64
, orbinary
, then the hash value will be encoded in the appropriate format. Ifencbuf
is a Buffer of at least 8 bytes, then the hash value will be written toencbuf
andencbuf
will be returned. The default value forencbuf
is'buffer'
.
XXHash Static Properties
Stream(< _mixed_ >seed[, < _integer_ >bits][, < _mixed_ >encbuf]) - DuplexStream - A stream constructor that takes in the
seed
to use. Write data to the stream and when the stream ends, abits
-bit (32 or 64) hash value (format determined byencbuf
) is available on the readable side. The values forseed
andencbuf
are described above inhash()
.XXHash64(< _mixed_ >seed) - This is the 64-bit Hash constructor. It is only needed if you want to use the old streaming interface (
update()
/digest()
) instead of the streams2 interface described above.
XXHash Methods
(constructor)(< _mixed_ >seed) - Creates and returns a new 32-bit Hash instance with the given
seed
. The values forseed
are described above inhash()
.update(< _Buffer_ >data) - (void) - Update the hash using
data
.digest([< _mixed_ >encbuf]) - mixed - The values for
encbuf
and the resulting hash value format is described inhash()
.