Files: 68d5803b6db1f8ca946875a36fd4b720cf8f8255 / index.js
656 bytesRaw
1 | var crypto = require('crypto') |
2 | |
3 | module.exports = function (type, encoding, onEnd) { |
4 | if (onEnd == null) onEnd = encoding, encoding = null |
5 | var hash = (typeof type == 'string') ? crypto.createHash(type) : type |
6 | var ended |
7 | function hasher(read) { |
8 | return function (abort, cb) { |
9 | read(abort, function (end, data) { |
10 | if (end === true && !hasher.digest) hasher.digest = hash.digest(encoding) |
11 | else if (!end) hash.update(data) |
12 | if (end && onEnd && !ended) { |
13 | onEnd(end === true ? null : end, hasher.digest) |
14 | ended = true |
15 | } |
16 | cb(end, data) |
17 | }) |
18 | } |
19 | } |
20 | hasher.hash = hash |
21 | return hasher |
22 | } |
23 |
Built with git-ssb-web