Files
kopia/cli/command_blob_show.go
Jarek Kowalski 514df69afa performance: added wrapper around io.Copy()
this pools copy buffers so they can be reused instead of throwing away
after each io.Copy()
2020-03-10 21:52:30 -07:00

38 lines
790 B
Go

package cli
import (
"bytes"
"context"
"os"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/iocopy"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/blob"
)
var (
blobShowCommand = blobCommands.Command("show", "Show contents of BLOBs").Alias("cat")
blobShowIDs = blobShowCommand.Arg("blobID", "Blob IDs").Required().Strings()
)
func runBlobShow(ctx context.Context, rep *repo.Repository) error {
for _, blobID := range *blobShowIDs {
d, err := rep.Blobs.GetBlob(ctx, blob.ID(blobID), 0, -1)
if err != nil {
return errors.Wrapf(err, "error getting %v", blobID)
}
if _, err := iocopy.Copy(os.Stdout, bytes.NewReader(d)); err != nil {
return err
}
}
return nil
}
func init() {
blobShowCommand.Action(repositoryAction(runBlobShow))
}