forked from alanshaw/ipfs-only-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·37 lines (33 loc) · 855 Bytes
/
cli.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
#!/usr/bin/env node
const fs = require('fs')
const meow = require('meow')
const Hash = require('.')
const cli = meow(`
Usage
# get the cid v1 for the file
$ ipfs-only-hash <file>
# get the cid v0 for data from stdin
$ echo "hello world" | ipfs-only-hash --cid-version 0
`, {
booleanDefault: undefined,
flags: {
cidVersion: {
type: 'number',
default: 1
},
rawLeaves: {
type: 'boolean',
}
}
})
async function main (cli) {
let stream = process.stdin
if (cli.input[0]) {
stream = fs.createReadStream(cli.input[0])
}
const cidVersion = cli.flags.cidVersion
const rawLeaves = (cidVersion === 1 && cli.flags.rawLeaves === undefined) ? true : cli.flags.rawLeaves;
const hash = await Hash.of(stream, { "cidVersion": cidVersion, "rawLeaves": rawLeaves })
console.log(hash)
}
main(cli)