Skip to content

Commit d2aa85d

Browse files
committed
refactor: add overflow interface
1 parent 66af2a0 commit d2aa85d

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

archiver.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,8 @@ func (a *Archiver) compress(file *pool.File) error {
184184
return errors.New("ERROR: could not create compressor")
185185
}
186186
hasher := crc32.NewIEEE()
187-
w := io.MultiWriter(compressor, hasher)
188187

189-
err = a.copy(w, file)
188+
err = a.copy(io.MultiWriter(compressor, hasher), file)
190189
if err != nil {
191190
return errors.Wrapf(err, "ERROR: could not read file %s", file.Path)
192191
}

archiver_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ func TestCompress(t *testing.T) {
164164
assert.True(t, file.Overflowed())
165165
assertGreaterThan(t, file.Written(), int64(file.CompressedData.Len()))
166166
assert.Equal(t, file.Written(), int64(file.Header.CompressedSize64))
167-
168-
assert.NotZero(t, file.Overflow)
169-
overflowInfo := testutils.GetFileInfo(t, file.Overflow.Name())
170-
assert.NotZero(t, overflowInfo.Size())
171167
})
172168

173169
t.Run("for directories", func(t *testing.T) {

pool/file.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package pool
33
import (
44
"archive/zip"
55
"bytes"
6+
"io"
67
"io/fs"
78
"os"
89
"path/filepath"
@@ -12,12 +13,17 @@ import (
1213

1314
const defaultBufferSize = 1000000
1415

16+
type Overflow interface {
17+
io.ReadWriteSeeker
18+
io.Closer
19+
}
20+
1521
type File struct {
1622
Path string
1723
Info fs.FileInfo
1824
CompressedData bytes.Buffer
1925
Header *zip.FileHeader
20-
Overflow *os.File
26+
Overflow Overflow
2127
written int64
2228
}
2329

0 commit comments

Comments
 (0)