remove ByteCounter from rootfs

This commit is contained in:
2021-05-24 00:11:58 +03:00
parent e1555f31a8
commit e2cf760c12
4 changed files with 29 additions and 31 deletions

View File

@@ -13,7 +13,11 @@ import (
)
type (
rootfsFactory func(io.ReadSeeker) io.WriterTo
flattener interface {
Flatten(io.Writer) error
}
rootfsFactory func(io.ReadSeeker) flattener
// Command is "rootfs" command
Command struct {
@@ -55,10 +59,7 @@ func (c *Command) Execute(args []string) (err error) {
out = outf
}
if _, err := c.rootfsNew(rd).WriteTo(out); err != nil {
return err
}
return nil
return c.rootfsNew(rd).Flatten(out)
}
// init() initializes Command with the default options.
@@ -67,7 +68,7 @@ func (c *Command) Execute(args []string) (err error) {
// command will initialize itself.
func (c *Command) init() {
c.BaseCommand.Init()
c.rootfsNew = func(r io.ReadSeeker) io.WriterTo {
c.rootfsNew = func(r io.ReadSeeker) flattener {
return rootfs.New(r)
}
}

View File

@@ -67,7 +67,7 @@ func TestExecute(t *testing.T) {
inf := filepath.Join(dir, tt.infile)
c.PositionalArgs.Infile = goflags.Filename(inf)
c.PositionalArgs.Outfile = tt.outfile
c.rootfsNew = func(r io.ReadSeeker) io.WriterTo {
c.rootfsNew = func(r io.ReadSeeker) flattener {
return &passthrough{r}
}
@@ -92,4 +92,7 @@ func TestExecute(t *testing.T) {
type passthrough struct{ r io.Reader }
func (p *passthrough) WriteTo(w io.Writer) (int64, error) { return io.Copy(w, p.r) }
func (p *passthrough) Flatten(w io.Writer) error {
_, err := io.Copy(w, p.r)
return err
}