Files
kopia/cli/command_blob_show.go
Jarek Kowalski 9e5d0beccd refactoring: renamed storage.Storage to blob.Storage
This updates the terminology everywhere - blocks become blobs and
`storage.Storage` becomes `blob.Storage`.

Also introduced blob.ID which is a specialized string type, that's
different from CABS block ID.

Also renamed CLI subcommands from `kopia storage` to `kopia blob`.

While at it introduced `block.ErrBlockNotFound` and
`object.ErrObjectNotFound` that do not leak from lower layers.
2019-06-01 14:10:35 -07:00

37 lines
749 B
Go

package cli
import (
"bytes"
"context"
"io"
"os"
"github.com/pkg/errors"
"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 := io.Copy(os.Stdout, bytes.NewReader(d)); err != nil {
return err
}
}
return nil
}
func init() {
blobShowCommand.Action(repositoryAction(runBlobShow))
}