-
Notifications
You must be signed in to change notification settings - Fork 311
/
compress.go
58 lines (46 loc) · 1.51 KB
/
compress.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
57
58
/*
Zip & Gzip Interfaces Use this instead of archive/zip and compress/gzip packages.
usage example
import "github.com/rudderlabs/rudder-server/utils/sysUtils"
var GZip sysUtils.GZipI = &sysUtils.GZip{}
or
var GZip sysUtils.GZipI = sysUtils.NewGZip()
...
GZip.NewWriter(...)
*/
//go:generate mockgen -destination=../../mocks/utils/sysUtils/mock_compress.go -package mock_sysUtils github.com/rudderlabs/rudder-server/utils/sysUtils GZipI
package sysUtils
import (
"compress/gzip"
"io"
)
type GZipI interface {
NewReader(r io.Reader) (*gzip.Reader, error)
NewWriter(w io.Writer) *gzip.Writer
}
type GZip struct{}
// NewZip returns a Zip instance
func NewGZip() GZipI {
return &GZip{}
}
// NewWriter returns a new Writer.
// Writes to the returned writer are compressed and written to w.
//
// It is the caller's responsibility to call Close on the Writer when done.
// Writes may be buffered and not flushed until Close.
//
// Callers that wish to set the fields in Writer.Header must do so before
// the first call to Write, Flush, or Close.
func (*GZip) NewWriter(w io.Writer) *gzip.Writer {
return gzip.NewWriter(w)
}
// NewReader creates a new Reader reading the given reader.
// If r does not also implement io.ByteReader,
// the decompressor may read more data than necessary from r.
//
// It is the caller's responsibility to call Close on the Reader when done.
//
// The Reader.Header fields will be valid in the Reader returned.
func (*GZip) NewReader(r io.Reader) (*gzip.Reader, error) {
return gzip.NewReader(r)
}