internal/multifile/compress.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | package multifile import ( "io" "os" "gitlab.com/tozd/go/errors" ) type CompressWriter struct { *os.File Writer io.WriteCloser } func NewCompressWriter(file *os.File, writer io.WriteCloser) *CompressWriter { return &CompressWriter{ File: file, Writer: writer, } } func (cw *CompressWriter) Write(p []byte) (int, error) { n, err := cw.Writer.Write(p) if err != nil { return 0, errors.WithStack(err) } return n, nil } func (cw *CompressWriter) Close() error { return errors.WithStack(errors.Join(cw.Writer.Close(), cw.File.Close())) } |