BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / hasha / readme.md

readme.md

Import template
timfa Tim · pushed by timfa · 4 years ago
c788ad20 History
readme.md 3.0 KiB Download Raw

<h1 align="center">


hasha




</h1>

> Hashing made simple. Get the hash of a buffer/string/stream/file.

Build Status

Convenience wrapper around the core crypto Hash class with simpler API and better defaults.

Install

$ npm install --save hasha

Usage

var hasha = require('hasha');

hasha('unicorn');
//=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'
var hasha = require('hasha');

// hash the process input and output the hash sum
process.stdin.pipe(hasha.stream()).pipe(process.stdout);
var hasha = require('hasha');

// get the MD5 hash of an image
hasha.fromFile('unicorn.png', {algorithm: 'md5'}).then(function (hash) {
	console.log(hash);
	//=> '1abcb33beeb811dca15f0ac3e47b88d9'
});

API

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

hasha(input, [options])

Returns a hash.

input

Type: buffer, string, array of string|buffer

Buffer you want to hash.

While strings are supported you should prefer buffers as they're faster to hash. Though 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

encoding

Type: string Default: hex Values: hex, base64, buffer, binary

Encoding of the returned hash.

algorithm

Type: string Default: sha512 Values: md5, sha1, sha256, sha512, etc (platform dependent)

The md5 algorithm is good for file revving, but you should never use md5 or sha1 for anything sensitive. They're insecure.

hasha.stream([options])

Returns a hash transform stream.

hasha.fromStream(stream, [options])

Returns a promise that resolves to a hash.

hasha.fromFile(filepath, [options])

Returns a promise that resolves to a hash.

hasha.fromFileSync(filepath, [options])

Returns a hash.

Resources

Related

License

MIT © Sindre Sorhus

Source
1<h1 align="center">
2 <br>
3 <br>
4 <br>
5 <img width="380" src="https://rawgit.com/sindresorhus/hasha/master/media/logo.svg" alt="hasha">
6 <br>
7 <br>
8 <br>
9 <br>
10 <br>
11</h1>
12
13> Hashing made simple. Get the hash of a buffer/string/stream/file.
14
15[![Build Status](https://travis-ci.org/sindresorhus/hasha.svg?branch=master)](https://travis-ci.org/sindresorhus/hasha)
16
17Convenience wrapper around the core [`crypto` Hash class](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm) with simpler API and better defaults.
18
19
20## Install
21
22```
23$ npm install --save hasha
24```
25
26
27## Usage
28
29```js
30var hasha = require('hasha');
31
32hasha('unicorn');
33//=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'
34```
35
36```js
37var hasha = require('hasha');
38
39// hash the process input and output the hash sum
40process.stdin.pipe(hasha.stream()).pipe(process.stdout);
41```
42
43```js
44var hasha = require('hasha');
45
46// get the MD5 hash of an image
47hasha.fromFile('unicorn.png', {algorithm: 'md5'}).then(function (hash) {
48 console.log(hash);
49 //=> '1abcb33beeb811dca15f0ac3e47b88d9'
50});
51```
52
53
54## API
55
56See the Node.js [`crypto` docs](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm) for more about hashing.
57
58### hasha(input, [options])
59
60Returns a hash.
61
62#### input
63
64Type: `buffer`, `string`, `array` of `string`|`buffer`
65
66Buffer you want to hash.
67
68While strings are supported you should prefer buffers as they're faster to hash. Though if you already have a string you should not convert it to a buffer.
69
70Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation.
71
72#### options
73
74##### encoding
75
76Type: `string`
77Default: `hex`
78Values: `hex`, `base64`, `buffer`, `binary`
79
80Encoding of the returned hash.
81
82##### algorithm
83
84Type: `string`
85Default: `sha512`
86Values: `md5`, `sha1`, `sha256`, `sha512`, etc *([platform dependent](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm))*
87
88*The `md5` algorithm is good for [file revving](https://github.com/sindresorhus/rev-hash), but you should never use `md5` or `sha1` for anything sensitive. [They're insecure.](http://googleonlinesecurity.blogspot.no/2014/09/gradually-sunsetting-sha-1.html)*
89
90### hasha.stream([options])
91
92Returns a [hash transform stream](https://nodejs.org/api/crypto.html#crypto_class_hash).
93
94### hasha.fromStream(stream, [options])
95
96Returns a promise that resolves to a hash.
97
98### hasha.fromFile(filepath, [options])
99
100Returns a promise that resolves to a hash.
101
102### hasha.fromFileSync(filepath, [options])
103
104Returns a hash.
105
106
107## Resources
108
109- [Hasha: A Friendly Crypto API • DailyJS](http://dailyjs.com/2015/06/12/hasha-a-friendly-crypto-api/)
110
111
112## Related
113
114- [hasha-cli](https://github.com/sindresorhus/hasha-cli) - CLI for this module
115- [hash-obj](https://github.com/sindresorhus/hash-obj) - Get the hash of an object
116
117
118## License
119
120MIT © [Sindre Sorhus](http://sindresorhus.com)