lotus/cmd/lotus-shed/fr32.go

57 lines
1011 B
Go
Raw Normal View History

2021-09-20 11:26:05 +00:00
package main
import (
"io"
"os"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi"
2022-06-14 15:00:51 +00:00
2021-09-20 11:26:05 +00:00
"github.com/filecoin-project/lotus/extern/sector-storage/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()
},
}