Skip to content

Commit

Permalink
Merge pull request #7355 from filecoin-project/feat/shed-fr32
Browse files Browse the repository at this point in the history
lotus shed: fr32 utils
  • Loading branch information
magik6k authored Sep 27, 2021
2 parents dbcb662 + 83c8e98 commit cd66afb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions cmd/lotus-shed/fr32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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/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()
},
}
1 change: 1 addition & 0 deletions cmd/lotus-shed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func main() {
minerTypesCmd,
minerMultisigsCmd,
splitstoreCmd,
fr32Cmd,
}

app := &cli.App{
Expand Down

0 comments on commit cd66afb

Please sign in to comment.