Esempio n. 1
0
func reader(t *testing.T, tname string, buf *bytes.Buffer, atype string, fname string) archive.ReadCloser {
	switch atype {
	case gzipType:
		gr, err := gzip.NewReader(buf, fname)
		if err != nil {
			t.Fatalf("%s: %v", tname, err)
		}
		return gr
	case tarType:
		return archive.NopCloser(tar.NewReader(buf))
	case zipType:
		zr, err := zip.NewReader(
			bytes.NewReader(buf.Bytes()),
			int64(buf.Len()))
		if err != nil {
			t.Fatalf("%s: new zip reader: %v", tname, err)
		}
		return archive.NopCloser(zr)
	}
	t.Fatalf("%s: unrecognized archive type: %s", tname, atype)
	panic("execution continued after (*testing.T).Fatalf")
}
Esempio n. 2
0
	rollingArchiveZip: {
		extension:             ".zip",
		handleMultipleEntries: true,
		archiver: func(f *os.File, _ bool) archive.WriteCloser {
			return zip.NewWriter(f)
		},
		unarchiver: func(f *os.File) (archive.ReadCloser, error) {
			fi, err := f.Stat()
			if err != nil {
				return nil, err
			}
			r, err := zip.NewReader(f, fi.Size())
			if err != nil {
				return nil, err
			}
			return archive.NopCloser(r), nil
		},
	},
	rollingArchiveGzip: {
		extension:             ".gz",
		handleMultipleEntries: false,
		archiver: func(f *os.File, exploded bool) archive.WriteCloser {
			gw := gzip.NewWriter(f)
			if exploded {
				return gw
			}
			return tar.NewWriteMultiCloser(gw, gw)
		},
		unarchiver: func(f *os.File) (archive.ReadCloser, error) {
			gr, err := gzip.NewReader(f, f.Name())
			if err != nil {