Documentation
¶
Index ¶
- Variables
- func AddExtension(filename string, algorithm *CompressionAlgorithm) string
- func HasAnyCompressionExtension(filename string) bool
- func HasCompressionExtension(filename string, algorithm *CompressionAlgorithm) bool
- func RemoveExtension(filename string) string
- type CompressionAlgorithm
- type Compressor
- func (c *Compressor) Compress(data *[]byte, algorithm *CompressionAlgorithm) ([]byte, error)
- func (c *Compressor) Decompress(data *[]byte, filename string) ([]byte, error)
- func (c *Compressor) NewReader(algorithm *CompressionAlgorithm, src io.Reader) (io.ReadCloser, error)
- func (c *Compressor) NewWriter(algorithm *CompressionAlgorithm, dst io.Writer) (io.WriteCloser, error)
Constants ¶
This section is empty.
Variables ¶
var ( Zstd = &CompressionAlgorithm{ Name: "zstd", Extension: ".zst", ContentEncoding: "zstd", } // Gzip is decode-only: nothing writes it anymore, but objects stored before the move to // zstd carry it and must stay readable and correctly labelled forever. Gzip = &CompressionAlgorithm{ Name: "gzip", Extension: ".gz", ContentEncoding: "gzip", } None = &CompressionAlgorithm{ Name: "none", Extension: "", ContentEncoding: "identity", } )
var Default = Zstd
Default is the algorithm new objects are written with.
var ErrUnsupportedAlgorithm = errors.New("unsupported compression algorithm")
ErrUnsupportedAlgorithm is returned when an unsupported compression algorithm is specified. It is always wrapped with the offending value, so callers should match it with errors.Is.
Functions ¶
func AddExtension ¶
func AddExtension(filename string, algorithm *CompressionAlgorithm) string
AddExtension adds the compression extension to the filename if it's not already present.
func HasAnyCompressionExtension ¶ added in v0.0.25
HasAnyCompressionExtension checks if the filename carries any compression extension.
func HasCompressionExtension ¶
func HasCompressionExtension(filename string, algorithm *CompressionAlgorithm) bool
HasCompressionExtension checks if the filename has the compression extension. A nil algorithm, or one with no extension of its own, matches nothing.
func RemoveExtension ¶
RemoveExtension removes the compression extension from the filename if it's present.
Types ¶
type CompressionAlgorithm ¶
CompressionAlgorithm represents the type of compression algorithm.
func GetCompressionAlgorithm ¶
func GetCompressionAlgorithm(filename string) (*CompressionAlgorithm, error)
GetCompressionAlgorithm resolves the algorithm a filename's extension implies.
func GetCompressionAlgorithmFromContentEncoding ¶ added in v0.0.25
func GetCompressionAlgorithmFromContentEncoding(contentEncoding string) (*CompressionAlgorithm, error)
GetCompressionAlgorithmFromContentEncoding resolves the algorithm a Content-Encoding names.
type Compressor ¶
type Compressor struct {
// contains filtered or unexported fields
}
Compressor provides methods for compressing and decompressing data.
A Compressor is safe for concurrent use and is meant to be built once and shared: the zstd encoder and decoder it holds are expensive to construct but cheap to reuse.
func NewCompressor ¶
func NewCompressor() *Compressor
NewCompressor creates a new Compressor instance.
func (*Compressor) Compress ¶
func (c *Compressor) Compress(data *[]byte, algorithm *CompressionAlgorithm) ([]byte, error)
Compress compresses the input data using the specified algorithm.
func (*Compressor) Decompress ¶
func (c *Compressor) Decompress(data *[]byte, filename string) ([]byte, error)
Decompress decompresses the input data, choosing the algorithm from the filename's extension.
func (*Compressor) NewReader ¶ added in v0.1.0
func (c *Compressor) NewReader(algorithm *CompressionAlgorithm, src io.Reader) (io.ReadCloser, error)
NewReader returns a reader that decompresses src using the given algorithm. The caller must Close the returned reader; closing it never closes src.
func (*Compressor) NewWriter ¶ added in v0.1.0
func (c *Compressor) NewWriter(algorithm *CompressionAlgorithm, dst io.Writer) (io.WriteCloser, error)
NewWriter returns a writer that compresses everything written to it into dst using the given algorithm. The caller must Close the returned writer to flush the trailing frame; closing it never closes dst.