func writer(t *testing.T, tname string, w io.Writer, atype string) archive.WriteCloser { switch atype { case gzipType: return gzip.NewWriter(w) case tarType: return tar.NewWriter(w) case zipType: return zip.NewWriter(w) } t.Fatalf("%s: unrecognized archive type: %s", tname, atype) panic("execution continued after (*testing.T).Fatalf") }
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 { return nil, err } // Determine if the gzip is a tar tr := tar.NewReader(gr) _, err = tr.Next() isTar := err == nil