Files
Miloslav Trmač 5e0b7e54c0 Avoid reliance on fs.ErrClosed in SparseWriter users
Neither of the SparseWriter users actually _wants_ the underlying
WriteSeeker to be closed; so, don't.

That makes it clear where the responsibility for closing the file
lies, and allows us to remove the reliance on the destinations
reliably returning ErrClosed.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-03-07 14:46:12 +01:00

32 lines
675 B
Go

package compression
import (
"io"
image "github.com/containers/image/v5/pkg/compression"
"github.com/sirupsen/logrus"
)
type gzipDecompressor struct {
genericDecompressor
}
func newGzipDecompressor(compressedFilePath string) (*gzipDecompressor, error) {
d, err := newGenericDecompressor(compressedFilePath)
return &gzipDecompressor{*d}, err
}
func (d *gzipDecompressor) decompress(w io.WriteSeeker, r io.Reader) error {
gzReader, err := image.GzipDecompressor(r)
if err != nil {
return err
}
defer func() {
if err := gzReader.Close(); err != nil {
logrus.Errorf("Unable to close gz file: %q", err)
}
}()
return d.sparseOptimizedCopy(w, gzReader)
}