-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
fr32.go
56 lines (47 loc) · 1004 Bytes
/
fr32.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
package main
import (
"io"
"os"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/storage/sealer/fr32"
)
var fr32Cmd = &cli.Command{
Name: "fr32",
Description: "fr32 encode/decode",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "decode",
Aliases: []string{"d"},
},
},
Action: func(context *cli.Context) error {
if context.Bool("decode") {
st, err := os.Stdin.Stat()
if err != nil {
return err
}
pps := abi.PaddedPieceSize(st.Size())
if pps == 0 {
return xerrors.Errorf("zero size input")
}
if err := pps.Validate(); err != nil {
return err
}
r, err := fr32.NewUnpadReader(os.Stdin, pps)
if err != nil {
return err
}
if _, err := io.Copy(os.Stdout, r); err != nil {
return err
}
return nil
}
w := fr32.NewPadWriter(os.Stdout)
if _, err := io.Copy(w, os.Stdin); err != nil {
return err
}
return w.Close()
},
}