-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.go
68 lines (51 loc) · 983 Bytes
/
zip.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
59
60
61
62
63
64
65
66
67
68
package pamphlet
import (
"archive/zip"
"io"
)
type ZipReaderCloser interface {
Close() error
Files() []*zip.File
}
type ZipReader struct {
reader *zip.Reader
}
type ZipReadCloser struct {
reader *zip.ReadCloser
}
func (z *ZipReader) Close() error {
return nil
}
func (z *ZipReadCloser) Close() error {
return z.reader.Close()
}
func (z *ZipReader) Files() []*zip.File {
return z.reader.File
}
func (z *ZipReadCloser) Files() []*zip.File {
return z.reader.File
}
type ZipFile struct {
file *zip.File
}
// Open opens the file in zip for reading
func (z *ZipFile) Open() (io.ReadCloser, error) {
return z.file.Open()
}
// GetRawContent returns the raw content of the file
func (c *ZipFile) GetRawContent() ([]byte, error) {
rc, err := c.Open()
if err != nil {
return nil, err
}
defer func(rc io.ReadCloser) {
err = rc.Close()
if err != nil {
}
}(rc)
content, err := io.ReadAll(rc)
if err != nil {
return nil, err
}
return content, nil
}