Files: 04c77cc71b341054c04792a9bc6c74aa4c18d225 / util.js
593 bytesRaw
1 | var crypto = require('crypto') |
2 | var pull = require('pull-stream') |
3 | |
4 | exports.createHash = function (type) { |
5 | var hash = crypto.createHash(type) |
6 | var hasher = pull.through(hash.update.bind(hash)) |
7 | var digest |
8 | hasher.hash = hash |
9 | hasher.digest = hash.digest.bind(hash) |
10 | hasher.readDigest = function (abort, cb) { |
11 | if (digest) cb(true) |
12 | else cb(null, digest = hash.digest()) |
13 | } |
14 | return hasher |
15 | } |
16 | |
17 | exports.createGitObjectHash = function (objectType, objectLength) { |
18 | var hasher = exports.createHash('sha1') |
19 | hasher.hash.update(objectType + ' ' + objectLength + '\0') |
20 | return hasher |
21 | } |
22 |
Built with git-ssb-web