ProductPromotion
Logo

Node.JS

made by https://0x3d.site

GitHub - sindresorhus/hasha: Hashing made simple. Get the hash of a buffer/string/stream/file.
Hashing made simple. Get the hash of a buffer/string/stream/file. - sindresorhus/hasha
Visit Site

GitHub - sindresorhus/hasha: Hashing made simple. Get the hash of a buffer/string/stream/file.

GitHub - sindresorhus/hasha: Hashing made simple. Get the hash of a buffer/string/stream/file.

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.

Install

npm install hasha

Usage

import {hash} from 'hasha';

await hash('unicorn');
//=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'

API

See the Node.js crypto docs for more about hashing.

hash(input, options?)

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.

hashSync(input, options?)

Returns a hash.

input

Type: Uint8Array | string | Array<Uint8Array | string> | NodeJS.ReadableStream (NodeJS.ReadableStream is not available in hashSync)

The value 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.

options

Type: object

encoding

Type: string
Default: 'hex'
Values: 'hex' | 'base64' | 'buffer' | 'latin1'

The encoding of the returned hash.

algorithm

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.

hashFile(filePath, options?)

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.

import {hashFile} from 'hasha';

// Get the MD5 hash of an image
await hashFile('unicorn.png', {algorithm: 'md5'});
//=> '1abcb33beeb811dca15f0ac3e47b88d9'

hashFileSync(filePath, options?)

Returns the calculated file hash.

import {hashFileSync} from 'hasha';

// Get the MD5 hash of an image
hashFileSync('unicorn.png', {algorithm: 'md5'});
//=> '1abcb33beeb811dca15f0ac3e47b88d9'

hashingStream(options?)

Returns a hash transform stream.

import {hashingStream} from 'hasha';

// Hash the process input and output the hash sum
process.stdin.pipe(hashingStream()).pipe(process.stdout);

Related

  • hasha-cli - CLI for this module
  • crypto-hash - Tiny hashing module that uses the native crypto API in Node.js and the browser
  • hash-object - Get the hash of an object
  • md5-hex - Create a MD5 hash with hex encoding

Articles
to learn more about the nodejs concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about NodeJS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory