forked from pgpkg/pgpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip_test.go
More file actions
63 lines (52 loc) · 1008 Bytes
/
zip_test.go
File metadata and controls
63 lines (52 loc) · 1008 Bytes
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
package pgpkg
import (
"archive/zip"
"bytes"
"fmt"
"io"
"log"
"os"
"testing"
)
func showZip(buf []byte) {
// Open a zip archive for reading.
readerAt := bytes.NewReader(buf)
r, err := zip.NewReader(readerAt, int64(len(buf)))
if err != nil {
panic(err)
}
// Iterate through the files in the archive,
// printing some of their contents.
for _, f := range r.File {
fmt.Printf("Contents of %s:\n", f.Name)
rc, err := f.Open()
if err != nil {
log.Fatal(err)
}
_, err = io.Copy(os.Stdout, rc)
//if err != nil {
// log.Fatal(err)
//}
rc.Close()
fmt.Println()
}
}
func TestZip(t *testing.T) {
// we don't currently have any zip files to test
t.SkipNow()
p, err := NewProjectFrom("tests/good/example")
if err != nil {
panic(err)
}
// in-memory zip
buf := new(bytes.Buffer)
zipWriter := zip.NewWriter(buf)
err = WriteProject(zipWriter, p)
if err != nil {
panic(err)
}
if err := zipWriter.Close(); err != nil {
panic(err)
}
showZip(buf.Bytes())
}