https://github.com/zkat/checksum-stream
Calculates and/or checks data coming through a stream and emits the digest before stream end.
https://github.com/zkat/checksum-stream
Last synced: 5 months ago
JSON representation
Calculates and/or checks data coming through a stream and emits the digest before stream end.
- Host: GitHub
- URL: https://github.com/zkat/checksum-stream
- Owner: zkat
- License: other
- Created: 2017-02-20T01:15:29.000Z (almost 9 years ago)
- Default Branch: latest
- Last Pushed: 2017-02-21T20:15:17.000Z (almost 9 years ago)
- Last Synced: 2024-12-27T20:46:14.190Z (12 months ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# checksum-stream [](https://npm.im/checksum-stream) [](https://npm.im/checksum-stream) [](https://travis-ci.org/zkat/checksum-stream) [](https://ci.appveyor.com/project/zkat/checksum-stream) [](https://coveralls.io/github/zkat/checksum-stream?branch=latest)
[`checksum-stream`](https://npm.im/checksum-stream) is a passthrough stream that calculates the digest and size for data piped through it. Before closing, it will emit `digest` and `size` events with the final stream size.
It can also be configured to error if `digest` or `size` do not matched a passed-in value that is expected for either or both. `size` errors will always be emitted first.
## Install
`$ npm install --save checksum-stream`
## Example
### npm repo
```javascript
const checksumStream = require('checksum-stream')
const fs = require('fs')
const request = require('request')
let req = request.get('https://npm.im/checksum-stream')
req.on('response', function (res) {
res.pipe(
checksumStream({
algorithm: 'sha256',
digest: res.headers['etag'],
size: res.headers['content-length']
}).on('error', e => throw e)
).pipe(
fs.createWriteStream('./checksum-stream.html')
)
})
```