Files: d2f2697f296dd39aed6a8b63c6d04a736a7db5b3 / node_modules / pull-hash / 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