-
Notifications
You must be signed in to change notification settings - Fork 16
/
reader_test.go
64 lines (57 loc) · 1.1 KB
/
reader_test.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
package zipstream
import (
"archive/zip"
"bytes"
"io"
"io/ioutil"
"math/rand"
"testing"
)
func TestReader(t *testing.T) {
testReader(t, []byte(`<poc><firstName>Juan</firstName></poc>`))
s := new(bytes.Buffer)
io.Copy(s, io.LimitReader(rand.New(rand.NewSource(1)), 16384))
testReader(t, s.Bytes())
}
func testReader(t *testing.T, s []byte) {
var wbuf bytes.Buffer
for j := 0; j < 2; j++ {
z := zip.NewWriter(&wbuf)
for i := 0; i < 2; i++ {
zw, err := z.Create("tmp")
if err != nil {
t.Fatal(err)
}
if _, err := zw.Write(s); err != nil {
t.Fatal(err)
}
}
if err := z.Close(); err != nil {
t.Fatal(err)
}
}
zr := NewReader(&wbuf)
for j := 0; j < 2; j++ {
fcount := 0
for {
_, err := zr.Next()
if err != nil {
if err != io.EOF {
t.Fatal(err)
}
if fcount != 2 {
t.Fatal("Embeded file missing", j, fcount, err)
}
break // No more files
}
fcount++
s2, err := ioutil.ReadAll(zr)
if err != nil {
t.Fatal(err)
}
if bytes.Compare(s, s2) != 0 {
t.Fatal("Decompressed data does not match original")
}
}
}
}