From 8141f7b6a6c913d9c0a59e76a58feb7319ad1a34 Mon Sep 17 00:00:00 2001 From: Ingar Shu Date: Fri, 23 Oct 2020 14:51:15 -0700 Subject: [PATCH] Expose ClientDealSize API via client stat CLI --- cli/client.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cli/client.go b/cli/client.go index b25a5e8ca..524fdf900 100644 --- a/cli/client.go +++ b/cli/client.go @@ -84,6 +84,7 @@ var clientCmd = &cli.Command{ WithCategory("data", clientImportCmd), WithCategory("data", clientDropCmd), WithCategory("data", clientLocalCmd), + WithCategory("data", clientStat), WithCategory("retrieval", clientFindCmd), WithCategory("retrieval", clientRetrieveCmd), WithCategory("util", clientCommPCmd), @@ -1639,6 +1640,39 @@ var clientInfoCmd = &cli.Command{ }, } +var clientStat = &cli.Command{ + Name: "stat", + Usage: "Print information about a locally stored file (piece size, etc)", + ArgsUsage: "", + Action: func(cctx *cli.Context) error { + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + if !cctx.Args().Present() || cctx.NArg() != 1 { + return fmt.Errorf("must specify cid of data") + } + + dataCid, err := cid.Parse(cctx.Args().First()) + if err != nil { + return fmt.Errorf("parsing data cid: %w", err) + } + + ds, err := api.ClientDealSize(ctx, dataCid) + if err != nil { + return err + } + + fmt.Printf("Piece Size : %v\n", ds.PieceSize) + fmt.Printf("Payload Size: %v\n", ds.PayloadSize) + + return nil + }, +} + var clientRestartTransfer = &cli.Command{ Name: "restart-transfer", Usage: "Force restart a stalled data transfer",