Files
kopia/cli/command_blob_show.go
Jarek Kowalski 6cb9b8fa4f repo: refactored public API (#318)
* This is 99% mechanical:

Extracted repo.Repository interface that only exposes high-level object and manifest management methods, but not blob nor content management.

Renamed old *repo.Repository to *repo.DirectRepository

Reviewed codebase to only depend on repo.Repository as much as possible, but added way for low-level CLI commands to use DirectRepository.

* PR fixes
2020-03-26 08:04:01 -07:00

38 lines
802 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.DirectRepository) 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(directRepositoryAction(runBlobShow))
}