Documentation
¶
Overview ¶
Package archive provides types and functions for working with ZSTD compressed archives.
Index ¶
Constants ¶
const ( // DefaultCompressionLevel is the default compression level for encoding. DefaultCompressionLevel = zstd.BestSpeed )
const HeaderSize = 24 // 4 + 4 + 8 + 8 bytes
HeaderSize is the fixed binary size of an archive header.
Variables ¶
var Magic = [4]byte{0x5a, 0x53, 0x54, 0x44} // "ZSTD"
Magic bytes identifying a ZSTD archive header.
Functions ¶
func Encode ¶
func Encode(dst io.WriteSeeker, data []byte, opts ...WriterOption) error
Encode compresses data and writes it as an archive to dst.
Types ¶
type Header ¶
type Header struct {
Magic [4]byte
HeaderLength uint32
Length uint64 // Uncompressed size
CompressedLength uint64 // Compressed size
}
Header represents the header of a compressed archive file.
func (*Header) DecodeFrom ¶
DecodeFrom reads the header from the given buffer. Does not validate - use UnmarshalBinary for validation.
func (*Header) EncodeTo ¶
EncodeTo writes the header to the given buffer. The buffer must be at least HeaderSize bytes.
func (*Header) MarshalBinary ¶
MarshalBinary encodes the header to binary format. Uses direct encoding to avoid allocations.
func (*Header) UnmarshalBinary ¶
UnmarshalBinary decodes the header from binary format. Uses direct decoding to avoid allocations.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps an io.ReadSeeker to provide decompression of archive data.
func NewReader ¶
func NewReader(r io.ReadSeeker) (*Reader, error)
NewReader creates a new archive reader from the given source. It reads and validates the header, then returns a reader for the decompressed content.
func (*Reader) CompressedLength ¶
CompressedLength returns the compressed data length.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer wraps an io.WriteSeeker to provide compression of archive data.
func NewWriter ¶
func NewWriter(dst io.WriteSeeker, uncompressedSize uint64, opts ...WriterOption) (*Writer, error)
NewWriter creates a new archive writer that writes to dst. The uncompressedSize is the expected size of the uncompressed data.
type WriterOption ¶
type WriterOption func(*Writer)
WriterOption configures a Writer.
func WithCompressionLevel ¶
func WithCompressionLevel(level int) WriterOption
WithCompressionLevel sets the compression level for the writer.