+
+ r, w := io.Pipe()
+ reader = r
+ closer = DummyCloser{}
+ fileSize += 2 * TarBlockSize // termination block
+
+ go func() error {
+ tarWr := tar.NewWriter(w)
+ hdr := tar.Header{
+ Typeflag: tar.TypeDir,
+ Mode: 0777,
+ PAXRecords: map[string]string{
+ "comment": "Autogenerated by " + VersionGet(),
+ },
+ Format: tar.FormatPAX,
+ }
+ for _, e := range dirs {
+ hdr.Name = basePath + e.path[len(rootPath):]
+ hdr.ModTime = e.modTime
+ if err = tarWr.WriteHeader(&hdr); err != nil {
+ return w.CloseWithError(err)
+ }
+ }
+ hdr.Typeflag = tar.TypeReg
+ hdr.Mode = 0666
+ for _, e := range files {
+ hdr.Name = basePath + e.path[len(rootPath):]
+ hdr.ModTime = e.modTime
+ hdr.Size = e.size
+ if err = tarWr.WriteHeader(&hdr); err != nil {
+ return w.CloseWithError(err)
+ }
+ fd, err := os.Open(e.path)
+ if err != nil {
+ fd.Close() // #nosec G104
+ return w.CloseWithError(err)
+ }
+ if _, err = io.Copy(tarWr, bufio.NewReader(fd)); err != nil {
+ fd.Close() // #nosec G104
+ return w.CloseWithError(err)
+ }
+ fd.Close() // #nosec G104
+ }
+ if err = tarWr.Close(); err != nil {
+ return w.CloseWithError(err)
+ }
+ return w.Close()
+ }()
+ return