summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/sha/README.md
blob: c881194c213cdbc51153faa7d879ee12c9e9f67e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# sha

Check and get file hashes (using any algorithm)

[![Build Status](https://img.shields.io/travis/ForbesLindesay/sha/master.svg)](https://travis-ci.org/ForbesLindesay/sha)
[![Dependency Status](https://img.shields.io/gemnasium/ForbesLindesay/sha.svg)](https://gemnasium.com/ForbesLindesay/sha)
[![NPM version](https://img.shields.io/npm/v/sha.svg)](http://badge.fury.io/js/sha)

## Installation

    $ npm install sha

## API

### check(fileName, expected, [options,] cb) / checkSync(filename, expected, [options])

Asynchronously check that `fileName` has a "hash" of `expected`.  The callback will be called with either `null` or an error (indicating that they did not match).

Options:

- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`

### get(fileName, [options,] cb) / getSync(filename, [options])

Asynchronously get the "hash" of `fileName`.  The callback will be called with an optional `error` object and the (lower cased) hex digest of the hash.

Options:

- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`

### stream(expected, [options])

Check the hash of a stream without ever buffering it.  This is a pass through stream so you can do things like:

```js
fs.createReadStream('src')
  .pipe(sha.stream('expected'))
  .pipe(fs.createWriteStream('dest'))
```

`dest` will be a complete copy of `src` and an error will be emitted if the hash did not match `'expected'`.

Options:

- algorithm: defaults to `sha1` and can be any of the algorithms supported by `crypto.createHash`

## License

You may use this software under the BSD or MIT.  Take your pick.  If you want me to release it under another license, open a pull request.