-
Notifications
You must be signed in to change notification settings - Fork 44
/
car.go
236 lines (231 loc) · 5.36 KB
/
car.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package main
import (
"log"
"os"
"github.com/multiformats/go-multicodec"
"github.com/urfave/cli/v2"
)
func main() { os.Exit(main1()) }
func main1() int {
app := &cli.App{
Name: "car",
Usage: "Utility for working with car files",
Commands: []*cli.Command{
{
Name: "compile",
Usage: "compile a car file from a debug patch",
Action: CompileCar,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Aliases: []string{"o", "f"},
Usage: "The file to write to",
TakesFile: true,
},
},
},
{
Name: "create",
Usage: "Create a car file",
Aliases: []string{"c"},
Action: CreateCar,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "file",
Aliases: []string{"f", "output", "o"},
Usage: "The car file to write to",
TakesFile: true,
},
&cli.BoolFlag{
Name: "no-wrap",
Usage: "Do not wrap the files in a directory",
},
&cli.IntFlag{
Name: "version",
Value: 2,
Usage: "Write output as a v1 or v2 format car",
},
},
},
{
Name: "debug",
Usage: "debug a car file",
Action: DebugCar,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Aliases: []string{"o", "f"},
Usage: "The file to write to",
TakesFile: true,
},
},
},
{
Name: "detach-index",
Usage: "Detach an index to a detached file",
Action: DetachCar,
Subcommands: []*cli.Command{{
Name: "list",
Usage: "List a detached index",
Action: DetachCarList,
}},
},
{
Name: "extract",
Aliases: []string{"x"},
Usage: "Extract the contents of a car when the car encodes UnixFS data",
Action: ExtractCar,
ArgsUsage: "[output directory|-]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "file",
Aliases: []string{"f"},
Usage: "The car file to extract from, or stdin if omitted",
Required: false,
TakesFile: true,
},
&cli.StringFlag{
Name: "path",
Aliases: []string{"p"},
Usage: "The unixfs path to extract",
Required: false,
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Usage: "Include verbose information about extracted contents",
},
},
},
{
Name: "filter",
Aliases: []string{"f"},
Usage: "Filter the CIDs in a car",
Action: FilterCar,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "cid-file",
Usage: "A file to read CIDs from",
TakesFile: true,
},
&cli.BoolFlag{
Name: "append",
Usage: "Append cids to an existing output file",
},
&cli.BoolFlag{
Name: "inverse",
Usage: "Inverse the filter (this will remove cids from the car file)",
Value: false,
},
&cli.IntFlag{
Name: "version",
Value: 2,
Usage: "Write output as a v1 or v2 format car",
},
},
},
{
Name: "get-block",
Aliases: []string{"gb"},
Usage: "Get a block out of a car",
Action: GetCarBlock,
},
{
Name: "get-dag",
Aliases: []string{"gd"},
Usage: "Get a dag out of a car",
Action: GetCarDag,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "selector",
Aliases: []string{"s"},
Usage: "A selector over the dag",
},
&cli.BoolFlag{
Name: "strict",
Usage: "Fail if the selector finds links to blocks not in the original car",
},
&cli.IntFlag{
Name: "version",
Value: 2,
Usage: "Write output as a v1 or v2 format car",
},
},
},
{
Name: "index",
Aliases: []string{"i"},
Usage: "write out the car with an index",
Action: IndexCar,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "codec",
Aliases: []string{"c"},
Usage: "The type of index to write",
Value: multicodec.CarMultihashIndexSorted.String(),
},
&cli.IntFlag{
Name: "version",
Value: 2,
Usage: "Write output as a v1 or v2 format car",
},
},
Subcommands: []*cli.Command{{
Name: "create",
Usage: "Write out a detached index",
Action: CreateIndex,
}},
},
{
Name: "inspect",
Usage: "verifies a car and prints a basic report about its contents",
Action: InspectCar,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "full",
Value: false,
Usage: "Check that the block data hash digests match the CIDs",
},
},
},
{
Name: "list",
Aliases: []string{"l", "ls"},
Usage: "List the CIDs in a car",
Action: ListCar,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Usage: "Include verbose information about contained blocks",
},
&cli.BoolFlag{
Name: "unixfs",
Usage: "List unixfs filesystem from the root of the car",
},
&cli.BoolFlag{
Name: "unixfs-blocks",
Usage: "List blocks of unixfs objects in the car",
},
},
},
{
Name: "root",
Usage: "Get the root CID of a car",
Action: CarRoot,
},
{
Name: "verify",
Aliases: []string{"v"},
Usage: "Verify a CAR is wellformed",
Action: VerifyCar,
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Println(err)
return 1
}
return 0
}