github.com/goreleaser/goreleaser@v1.25.1/pkg/archive/tarxz/tarxz.go (about)

     1  // Package tarxz implements the Archive interface providing tar.xz archiving
     2  // and compression.
     3  package tarxz
     4  
     5  import (
     6  	"io"
     7  
     8  	"github.com/goreleaser/goreleaser/pkg/archive/tar"
     9  	"github.com/goreleaser/goreleaser/pkg/config"
    10  	"github.com/ulikunitz/xz"
    11  )
    12  
    13  // Archive as tar.xz.
    14  type Archive struct {
    15  	xzw *xz.Writer
    16  	tw  *tar.Archive
    17  }
    18  
    19  // New tar.xz archive.
    20  func New(target io.Writer) Archive {
    21  	xzw, _ := xz.WriterConfig{DictCap: 16 * 1024 * 1024}.NewWriter(target)
    22  	tw := tar.New(xzw)
    23  	return Archive{
    24  		xzw: xzw,
    25  		tw:  &tw,
    26  	}
    27  }
    28  
    29  // Close all closeables.
    30  func (a Archive) Close() error {
    31  	if err := a.tw.Close(); err != nil {
    32  		return err
    33  	}
    34  	return a.xzw.Close()
    35  }
    36  
    37  // Add file to the archive.
    38  func (a Archive) Add(f config.File) error {
    39  	return a.tw.Add(f)
    40  }