Skip to content

Commit d529560

Browse files
authored
Merge pull request #2 from filedrive-team/feature
Retrieve file from CAR
2 parents 15cb0ba + bf7b542 commit d529560

File tree

6 files changed

+304
-9
lines changed

6 files changed

+304
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515

1616
# Dependency directories (remove the comment below to include it)
1717
# vendor/
18+
19+
.idea

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: build
2+
build:
3+
go build -ldflags "-s -w" -o graphsplit graphsplit.go utils.go retrieve.go

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Graphsplit has solved the problem we faced above. It takes advantage of IPLD con
1111

1212
## Build
1313
```sh
14-
go build -o graphsplit graphsplit.go utils.go
14+
make
1515
```
1616

1717
## Usage
@@ -43,6 +43,17 @@ Import car file to IPFS:
4343
ipfs dag import /path/to/car-dir/car-file
4444
```
4545

46+
Retrieve files:
47+
```sh
48+
# car-path: directory or file, in form of .car
49+
# output-dir: usually just be the same as /path/to/output-dir
50+
# parallel: number goroutines run when retrieving
51+
./graphsplit retrieve \
52+
--car-path=/path/to/car-path \
53+
--output-dir=/path/to/output-dir \
54+
--parallel=2
55+
```
56+
4657
## Contribute
4758

4859
PRs are welcome!

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/ipfs/go-ipfs-blockstore v1.0.3
1313
github.com/ipfs/go-ipfs-chunker v0.0.5
1414
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
15+
github.com/ipfs/go-ipfs-files v0.0.8
1516
github.com/ipfs/go-ipld-cbor v0.0.5-0.20200204214505-252690b78669 // indirect
1617
github.com/ipfs/go-ipld-format v0.2.0
1718
github.com/ipfs/go-log/v2 v2.1.2

graphsplit.go

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package main
33
import (
44
"context"
55
"fmt"
6-
"os"
7-
86
logging "github.com/ipfs/go-log/v2"
97
_ "github.com/jinzhu/gorm/dialects/mysql"
108
"github.com/urfave/cli/v2"
119
"golang.org/x/xerrors"
10+
"os"
1211
)
1312

1413
var log = logging.Logger("graphsplit")
@@ -17,6 +16,7 @@ func main() {
1716
logging.SetLogLevel("*", "INFO")
1817
local := []*cli.Command{
1918
chunkCmd,
19+
retrieveCmd,
2020
}
2121

2222
app := &cli.App{
@@ -33,31 +33,32 @@ func main() {
3333

3434
var chunkCmd = &cli.Command{
3535
Name: "chunk",
36-
Usage: "",
36+
Usage: "Generate CAR files of the specified size",
3737
Flags: []cli.Flag{
3838
&cli.Int64Flag{
3939
Name: "slice-size",
4040
Value: 17179869184, // 16G
41-
Usage: fmt.Sprintf("specify chunk piece size"),
41+
Usage: "specify chunk piece size",
4242
},
4343
&cli.IntFlag{
4444
Name: "parallel",
4545
Value: 4,
46-
Usage: fmt.Sprintf("specify how many number of goroutines runs when generate file node"),
46+
Usage: "specify how many number of goroutines runs when generate file node",
4747
},
4848
&cli.StringFlag{
4949
Name: "graph-name",
5050
Required: true,
51-
Usage: fmt.Sprintf("specify graph name"),
51+
Usage: "specify graph name",
5252
},
5353
&cli.StringFlag{
5454
Name: "parent-path",
5555
Value: "",
56-
Usage: fmt.Sprintf("specify graph parent path"),
56+
Usage: "specify graph parent path",
5757
},
5858
&cli.StringFlag{
5959
Name: "car-dir",
6060
Required: true,
61+
Usage: "specify output CAR directory",
6162
},
6263
},
6364
Action: func(c *cli.Context) error {
@@ -73,6 +74,9 @@ var chunkCmd = &cli.Command{
7374
if sliceSize == 0 {
7475
return xerrors.Errorf("Unexpected! Slice size has been set as 0")
7576
}
77+
if parallel <= 0 {
78+
return xerrors.Errorf("Unexpected! Parallel has to be greater than 0")
79+
}
7680

7781
args := c.Args().Slice()
7882
sliceTotal := GetGraphCount(args, sliceSize)
@@ -154,7 +158,6 @@ var chunkCmd = &cli.Command{
154158
}
155159

156160
}
157-
158161
}
159162
if cumuSize > 0 {
160163
// todo build ipld from graphFiles
@@ -166,3 +169,39 @@ var chunkCmd = &cli.Command{
166169
return nil
167170
},
168171
}
172+
173+
var retrieveCmd = &cli.Command{
174+
Name: "retrieve",
175+
Usage: "Retrieve files from CAR files",
176+
Flags: []cli.Flag{
177+
&cli.StringFlag{
178+
Name: "car-path",
179+
Required: true,
180+
Usage: "specify source car path, directory or file",
181+
},
182+
&cli.StringFlag{
183+
Name: "output-dir",
184+
Required: true,
185+
Usage: "specify output directory",
186+
},
187+
&cli.IntFlag{
188+
Name: "parallel",
189+
Value: 4,
190+
Usage: "specify how many number of goroutines runs when generate file node",
191+
},
192+
},
193+
Action: func(c *cli.Context) error {
194+
parallel := c.Int("parallel")
195+
outputDir := c.String("output-dir")
196+
carPath := c.String("car-path")
197+
if parallel <= 0 {
198+
return xerrors.Errorf("Unexpected! Parallel has to be greater than 0")
199+
}
200+
201+
CarTo(carPath, outputDir, parallel)
202+
Merge(outputDir, parallel)
203+
204+
fmt.Println("completed!")
205+
return nil
206+
},
207+
}

0 commit comments

Comments
 (0)