-
Notifications
You must be signed in to change notification settings - Fork 9
/
bin.js
executable file
·46 lines (35 loc) · 994 Bytes
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env node
var path = require('path')
var Blobs = require('./')
var pull = require('pull-stream')
var toPull = require('stream-to-pull-stream')
var u = require('./util')
var createHash = u.createHash
var cmd = process.argv[2], arg = process.argv[3]
var dir = path.join(process.env.HOME, 'tmp', 'multiblob')
var blobs = Blobs(dir)
if(cmd === 'add')
pull(
toPull.source(process.stdin),
blobs.add(arg, function (err, hash) {
if(err) throw err
console.log(hash)
})
)
if(cmd === 'get')
pull(blobs.get(arg), toPull.sink(process.stdout))
if(cmd === 'has')
blobs.has(arg, function (err) {
if(err) throw err
console.error('okay')
})
if(cmd === 'ls' || cmd === 'list')
pull(blobs.ls(), pull.drain(console.log))
if(cmd === 'hash') {
var hasher = createHash('sha256')
pull(toPull.source(process.stdin), hasher, pull.drain(null, function () {
console.log(hasher.digest)
}))
}
if(cmd === 'resolve')
console.log(blobs.resolve(arg))