示例#1
0
func printContents(filename string) {
	fmt.Println("file ", filename)
	file, err := os.Open(filename)
	if err != nil {
		fmt.Printf("Error while opening file:\n %s\n", err)
		return
	}
	reader, err := ar.NewReader(file)
	if err != nil {
		fmt.Printf("Error on NewReader\n %s\n", err)
	}
	defer reader.Free()
	defer reader.Close()
	for {
		entry, err := reader.Next()
		if err != nil {
			fmt.Printf("Error on reader.Next():\n%s\n", err)
			return
		}
		fmt.Printf("Name %s\n", entry.PathName())
		var buf bytes.Buffer
		size, err := buf.ReadFrom(reader)

		if err != nil {
			fmt.Printf("Error on reading entry from archive:\n%s\n", err)
		}
		if size > 0 {
			fmt.Println("Contents:\n***************", buf.String(), "*********************")
		}
	}
}
示例#2
0
func BenchTestFuncLib(b *testing.B, file io.Reader) {
	reader, _ := ar.NewReader(file)
	defer reader.Free()
	defer reader.Close()
	runBenchTest(b, wrapLibArchive(reader))
}