-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
zip_reader.go
47 lines (38 loc) · 830 Bytes
/
zip_reader.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
package opc
import (
"archive/zip"
"io"
)
type zipFile struct {
f *zip.File
}
func (zf *zipFile) Open() (io.ReadCloser, error) {
return zf.f.Open()
}
func (zf *zipFile) Name() string {
return zf.f.Name
}
func (zf *zipFile) Size() int {
return int(zf.f.UncompressedSize64)
}
type zipArchive struct {
r *zip.Reader
}
func newZipReader(r io.ReaderAt, size int64) (*zipArchive, error) {
zr, err := zip.NewReader(r, size)
if err != nil {
return nil, err
}
return &zipArchive{zr}, nil
}
func (z *zipArchive) Files() []archiveFile {
files := z.r.File
ret := make([]archiveFile, len(files))
for i := 0; i < len(files); i++ {
ret[i] = &zipFile{files[i]}
}
return ret
}
func (z *zipArchive) RegisterDecompressor(method uint16, dcomp func(r io.Reader) io.ReadCloser) {
z.r.RegisterDecompressor(method, dcomp)
}