git ssb

0+

cel / pull-git-remote-helper



Tree: b390ecc4bf4d610b201252d8a8a0cd1ad8cd2748

Files: b390ecc4bf4d610b201252d8a8a0cd1ad8cd2748 / lib / util.js

878 bytesRaw
1var crypto = require('crypto')
2var pull = require('pull-stream')
3
4exports.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
17exports.createGitObjectHash = function (objectType, objectLength) {
18 var hasher = exports.createHash('sha1')
19 hasher.hash.update(objectType + ' ' + objectLength + '\0')
20 return hasher
21}
22
23exports.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
31exports.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