Files: 1c27109b9155b4dd90f5068566dfc45b92a17f82 / lib / util.js
878 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 | |
23 | exports.split2 = function (str, delim) { |
24 | var i = str.indexOf(delim || ' ') |
25 | return (i === -1) ? [str, ''] : [ |
26 | str.substr(0, i), |
27 | str.substr(i + 1) |
28 | ] |
29 | } |
30 | |
31 | exports.split3 = function (str) { |
32 | var args = exports.split2(str) |
33 | return [args[0]].concat(exports.split2(args[1])) |
34 | } |
35 |
Built with git-ssb-web