diff --git a/src/cmd/linuxkit/initrd/initrd.go b/src/cmd/linuxkit/initrd/initrd.go index f6fb5bb76..1475373f1 100644 --- a/src/cmd/linuxkit/initrd/initrd.go +++ b/src/cmd/linuxkit/initrd/initrd.go @@ -9,14 +9,12 @@ import ( // drop-in 100% compatible replacement and 17% faster than compress/gzip. gzip "github.com/klauspost/pgzip" - "github.com/linuxkit/linuxkit/src/cmd/linuxkit/pad4" "github.com/surma/gocpio" ) // Writer is an io.WriteCloser that writes to an initrd // This is a compressed cpio archive, zero padded to 4 bytes type Writer struct { - pw *pad4.Writer gw *gzip.Writer cw *cpio.Writer } @@ -136,8 +134,7 @@ func CopySplitTar(w *Writer, r *tar.Reader) (kernel []byte, cmdline string, ucod // NewWriter creates a writer that will output an initrd stream func NewWriter(w io.Writer) *Writer { initrd := new(Writer) - initrd.pw = pad4.NewWriter(w) - initrd.gw = gzip.NewWriter(initrd.pw) + initrd.gw = gzip.NewWriter(w) initrd.cw = cpio.NewWriter(initrd.gw) return initrd @@ -157,15 +154,11 @@ func (w *Writer) Write(b []byte) (n int, e error) { func (w *Writer) Close() error { err1 := w.cw.Close() err2 := w.gw.Close() - err3 := w.pw.Close() if err1 != nil { return err1 } if err2 != nil { return err2 } - if err3 != nil { - return err3 - } return nil } diff --git a/src/cmd/linuxkit/pad4/pad4.go b/src/cmd/linuxkit/pad4/pad4.go deleted file mode 100644 index e78490fbe..000000000 --- a/src/cmd/linuxkit/pad4/pad4.go +++ /dev/null @@ -1,46 +0,0 @@ -package pad4 - -import ( - "bytes" - "io" -) - -// A Writer is an io.WriteCloser. Writes are padded with zeros to 4 byte boundary -type Writer struct { - w io.Writer - count int -} - -// Write writes output -func (pad *Writer) Write(p []byte) (int, error) { - n, err := pad.w.Write(p) - if err != nil { - return 0, err - } - pad.count += n - return n, nil -} - -// Close adds the padding -func (pad *Writer) Close() error { - mod4 := pad.count & 3 - if mod4 == 0 { - return nil - } - zero := make([]byte, 4-mod4) - buf := bytes.NewBuffer(zero) - n, err := io.Copy(pad.w, buf) - if err != nil { - return err - } - pad.count += int(n) - return nil -} - -// NewWriter provides a new io.WriteCloser that zero pads the -// output to a multiple of four bytes -func NewWriter(w io.Writer) *Writer { - pad := new(Writer) - pad.w = w - return pad -}