mirror of
https://github.com/kopia/kopia.git
synced 2026-01-26 07:18:02 -05:00
this pools copy buffers so they can be reused instead of throwing away after each io.Copy()
37 lines
683 B
Go
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))
|
|
}
|