-
Notifications
You must be signed in to change notification settings - Fork 307
/
archive.go
56 lines (45 loc) · 1.52 KB
/
archive.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Zip & Gzip Interfaces Use this instead of archive/zip and compress/gzip packages.
usage example
import "github.com/rudderlabs/rudder-server/utils/sysUtils"
var Zip sysUtils.ZipI = &sysUtils.Zip{}
or
var Zip sysUtils.ZipI = sysUtils.NewZip()
...
Zip.OpenReader(...)
*/
//go:generate mockgen -destination=../../mocks/utils/sysUtils/mock_archive.go -package mock_sysUtils github.com/rudderlabs/rudder-server/utils/sysUtils ZipI
package sysUtils
import (
"archive/zip"
"io"
"os"
)
type ZipI interface {
NewWriter(w io.Writer) *zip.Writer
FileInfoHeader(fi os.FileInfo) (*zip.FileHeader, error)
OpenReader(name string) (*zip.ReadCloser, error)
}
type Zip struct{}
// NewZip returns a Zip instance
func NewZip() ZipI {
return &Zip{}
}
// NewWriter returns a new Writer writing a zip file to w.
func (*Zip) NewWriter(w io.Writer) *zip.Writer {
return zip.NewWriter(w)
}
// FileInfoHeader creates a partially-populated FileHeader from an
// os.FileInfo.
// Because os.FileInfo's Name method returns only the base name of
// the file it describes, it may be necessary to modify the Name field
// of the returned header to provide the full path name of the file.
// If compression is desired, callers should set the FileHeader.Method
// field; it is unset by default.
func (*Zip) FileInfoHeader(fi os.FileInfo) (*zip.FileHeader, error) {
return zip.FileInfoHeader(fi)
}
// OpenReader will open the Zip file specified by name and return a ReadCloser.
func (*Zip) OpenReader(name string) (*zip.ReadCloser, error) {
return zip.OpenReader(name)
}