Ejemplo 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")
}
Ejemplo n.º 2
0
			}
			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 {
				return nil, err
			}

			// Determine if the gzip is a tar
			tr := tar.NewReader(gr)
			_, err = tr.Next()
			isTar := err == nil

			// Reset to beginning of file
			if _, err := f.Seek(0, os.SEEK_SET); err != nil {
				return nil, err
			}
			gr.Reset(f)