Files
kopia/cli/command_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

37 lines
683 B
Go

package cli
import (
"context"
"os"
"github.com/kopia/kopia/internal/iocopy"
"github.com/kopia/kopia/repo"
)
var (
catCommand = app.Command("show", "Displays contents of a repository object.").Alias("cat")
catCommandPath = catCommand.Arg("object-path", "Path").Required().String()
)
func runCatCommand(ctx context.Context, rep *repo.Repository) error {
oid, err := parseObjectID(ctx, rep, *catCommandPath)
if err != nil {
return err
}
r, err := rep.Objects.Open(ctx, oid)
if err != nil {
return err
}
defer r.Close() //nolint:errcheck
_, err = iocopy.Copy(os.Stdout, r)
return err
}
func init() {
catCommand.Action(repositoryAction(runCatCommand))
}