This repository was archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipfs.nu
More file actions
78 lines (65 loc) · 1.58 KB
/
ipfs.nu
File metadata and controls
78 lines (65 loc) · 1.58 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def get-last-to-next [nb_chars: int] {
split chars
| reverse
| skip 1
| take $nb_chars
| reverse
| str join
}
def "path add extension" [extension: string] {
path parse
| upsert extension $extension
| path join
}
# TODO: docstring
export def "struct ls" [
hash: string # TODO: arg
] {
ipfs ls $hash
| lines
| parse "{hash} {size}"
}
# TODO: docstring
export def "chunk add" [
file: string # TODO: arg
chunkers = [size-256144] # TODO: arg
] {
let results = (
$chunkers
| each {|chunker|
let hash = (ipfs add --quieter $file --chunker $chunker)
{
hash: $hash
chunker: $chunker
links: (ipfs dag get $hash | from json | get Links | length)
data: (ipfs dag get $hash | from json | get Data./.bytes | split chars | length)
}
}
)
$results
}
# TODO: docstring
export def "cid unpack" [
cid: string # TODO: arg
format: string = "base: %b\ncodec: %c\nhash name: %h\nmultihash: %m\ndigest: %d\ncid: %s" # TODO: arg
] {
ipfs cid format -f $format $cid
| lines
| split column ": "
| transpose -rid
}
# TODO: docstring
export def "block open" [
cid: string # TODO: arg
] {
let multihash = (ipfs cid format -f "%M" $cid | str upcase)
let prefix = ($multihash | get-last-to-next 2)
let block = ($prefix | path join $multihash)
let block_path = (
$env | get -i IPFS_PATH | default ($env.HOME | path join .ipfs)
| path join blocks $block
| path add extension data
)
print $"(ansi red_bold)($block)(ansi white_dimmed) at ($block_path)(ansi reset):"
open $block_path | into binary
}