Philipp Partosch 46a936d7de added all files to project | 2 years ago | |
---|---|---|
.. | ||
node_modules/type-fest | 2 years ago | |
index.d.ts | 2 years ago | |
index.js | 2 years ago | |
license | 2 years ago | |
package.json | 2 years ago | |
readme.md | 2 years ago | |
thread.js | 2 years ago |
Hashing made simple. Get the hash of a buffer/string/stream/file.
Convenience wrapper around the core crypto
Hash class with simpler API and better defaults.
$ npm install hasha
const hasha = require('hasha');
hasha('unicorn');
//=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'
const hasha = require('hasha');
(async () => {
console.log(await hasha.async('unicorn'));
//=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'
})();
const hasha = require('hasha');
// Hash the process input and output the hash sum
process.stdin.pipe(hasha.stream()).pipe(process.stdout);
const hasha = require('hasha');
(async () => {
// Get the MD5 hash of an image
const hash = await hasha.fromFile('unicorn.png', {algorithm: 'md5'});
console.log(hash);
//=> '1abcb33beeb811dca15f0ac3e47b88d9'
})();
See the Node.js crypto
docs for more about hashing.
Returns a hash.
Type: Buffer | string | Array<Buffer | string>
Buffer you want to hash.
While strings are supported you should prefer buffers as they’re faster to hash. Although if you already have a string you should not convert it to a buffer.
Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation.
Type: object
Type: string
\
Default: 'hex'
\
Values: 'hex' | 'base64' | 'buffer' | 'latin1'
Encoding of the returned hash.
Type: string
\
Default: 'sha512'
\
Values: 'md5' | 'sha1' | 'sha256' | 'sha512'
(Platform dependent)
The md5
algorithm is good for file revving, but you should never use md5
or sha1
for anything sensitive. They’re insecure.
In Node.js 12 or later, the operation is executed using worker_threads
. A thread is lazily spawned on the first operation and lives until the end of the program execution. It’s unrefed, so it won’t keep the process alive.
Returns a hash asynchronously.
Returns a hash transform stream.
Returns a Promise
for the calculated hash.
In Node.js 12 or later, the operation is executed using worker_threads
. A thread is lazily spawned on the first operation and lives until the end of the program execution. It’s unrefed, so it won’t keep the process alive.
Returns a Promise
for the calculated file hash.
Returns the calculated file hash.