Example #1
0
func testZipArc(f *bytes.Reader) {
	za, err := New(&reader{f}, f.Size())
	if err != nil {
		panic(err)
	}

	compareFile(za, "a.txt", "This is a file.\n")
	compareFile(za, "k/l/m/a.txt", "k-l-m-a!\n")
	compareFile(za, "z.txt", "This is also a file.\n")

	d, err := za.Open("a")
	if err != nil {
		panic(err)
	}

	dfi, err := d.Readdir(0)
	if err != nil {
		panic(err)
	}

	h := sha256.New()
	for _, x := range dfi {
		s := fmt.Sprintf("%v\t%v\t%v\t%v\n", x.Name(), x.IsDir(), x.Mode(), x.Size())
		h.Write([]byte(s))
	}
	hs := hex.EncodeToString(h.Sum(nil))
	if hs != "93d5c5b0a7a5205b5ad687a8726dbec1a355a3937151ca96f7e704675ae1e536" {
		panic("hash mismatch: " + hs)
	}
}