### Install gozstd Source: https://pkg.go.dev/github.com/valyala/gozstd Use the go get command to add the package to your project. ```bash go get -u github.com/valyala/gozstd ``` -------------------------------- ### Example Output Source: https://pkg.go.dev/github.com/valyala/gozstd Displays the expected output format for the example operation. ```text Output: err: line 0 line 1 line 2 ``` -------------------------------- ### Cross-compilation error Source: https://pkg.go.dev/github.com/valyala/gozstd Example of undefined symbol errors encountered during cross-compilation without proper CGO configuration. ```text # github.com/valyala/gozstd /go/pkg/mod/github.com/valyala/gozstd@v1.6.2/stream.go:31:59: undefined: CDict /go/pkg/mod/github.com/valyala/gozstd@v1.6.2/stream.go:35:64: undefined: CDict /go/pkg/mod/github.com/valyala/gozstd@v1.6.2/stream.go:47:20: undefined: Writer ``` -------------------------------- ### Cross-compile with CGO Source: https://pkg.go.dev/github.com/valyala/gozstd Enable CGO and specify a cross-compiler to build for different architectures. ```bash env CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 go build ./main.go ``` -------------------------------- ### Writer Configuration Parameters Source: https://pkg.go.dev/github.com/valyala/gozstd Defines compression settings including level, window log, and optional dictionary. ```go type WriterParams struct { // Compression level. Special value 0 means 'default compression level'. CompressionLevel int // WindowLog. Must be clamped between WindowLogMin and WindowLogMin32/64. // Special value 0 means 'use default windowLog'. // // Note: enabling log distance matching increases memory usage for both // compressor and decompressor. When set to a value greater than 27, the // decompressor requires special treatment. WindowLog int // Dict is optional dictionary used for compression. Dict *CDict } ``` -------------------------------- ### BuildDict Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to build a dictionary from samples for Zstandard compression. ```go func BuildDict(samples [][]byte, desiredDictLen int) []byte ``` -------------------------------- ### Define Window Log Constants Source: https://pkg.go.dev/github.com/valyala/gozstd Constants defining the minimum and maximum window log parameters for zstd compression. ```go const ( // WindowLogMin is the minimum value of the windowLog parameter. WindowLogMin = 10 // from zstd.h // WindowLogMax32 is the maximum value of the windowLog parameter on 32-bit architectures. WindowLogMax32 = 30 // from zstd.h // WindowLogMax64 is the maximum value of the windowLog parameter on 64-bit architectures. WindowLogMax64 = 31 // from zstd.h // DefaultWindowLog is the default value of the windowLog parameter. DefaultWindowLog = 0 ) ``` -------------------------------- ### func BuildDict Source: https://pkg.go.dev/github.com/valyala/gozstd Builds a dictionary from the provided samples for use in dictionary-based compression. ```APIDOC ## func BuildDict(samples [][]byte, desiredDictLen int) []byte ### Description Builds a dictionary from the given samples. The resulting dictionary size will be close to desiredDictLen. ### Parameters - **samples** ([][]byte) - The input samples to build the dictionary from. - **desiredDictLen** (int) - The target length for the resulting dictionary. ### Returns - **[]byte** - The generated dictionary. ``` -------------------------------- ### Compress data Source: https://pkg.go.dev/github.com/valyala/gozstd Use the Compress function for simple data compression. ```go compressedData := Compress(nil, data) ``` -------------------------------- ### Rebuild libzstd Source: https://pkg.go.dev/github.com/valyala/gozstd Commands to clean and rebuild the static library with custom flags. ```bash make clean libzstd.a ``` ```bash MOREFLAGS=-fPIC make clean libzstd.a ``` -------------------------------- ### Create new DDict Source: https://pkg.go.dev/github.com/valyala/gozstd Initializes a new DDict from the provided byte slice. Call Release when the dictionary is no longer needed. ```go func NewDDict(dict []byte) (*DDict, error) ``` -------------------------------- ### Create new Writer with parameters Source: https://pkg.go.dev/github.com/valyala/gozstd Returns a new zstd writer using the provided WriterParams. Must be closed with Close to finalize the stream. ```go func NewWriterParams(w io.Writer, params *WriterParams) *Writer ``` -------------------------------- ### Create new Reader Source: https://pkg.go.dev/github.com/valyala/gozstd Returns a new zstd reader for the provided io.Reader. Call Release when the reader is no longer needed. ```go func NewReader(r io.Reader) *Reader ``` -------------------------------- ### Create new Writer with compression level Source: https://pkg.go.dev/github.com/valyala/gozstd Returns a new zstd writer with a specific compression level. Must be closed with Close to finalize the stream. ```go func NewWriterLevel(w io.Writer, compressionLevel int) *Writer ``` -------------------------------- ### Create new Writer Source: https://pkg.go.dev/github.com/valyala/gozstd Returns a new zstd writer. Must be closed with Close to finalize the stream, and Release should be called when finished. ```go func NewWriter(w io.Writer) *Writer ``` -------------------------------- ### Create new Reader with DDict Source: https://pkg.go.dev/github.com/valyala/gozstd Returns a new zstd reader using the specified DDict. Call Release when the reader is no longer needed. ```go func NewReaderDict(r io.Reader, dd *DDict) *Reader ``` -------------------------------- ### CompressDict Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to compress a byte slice using a pre-built dictionary. ```go func CompressDict(dst, src []byte, cd *CDict) []byte ``` -------------------------------- ### func NewCDict Source: https://pkg.go.dev/github.com/valyala/gozstd Creates a new compression dictionary. ```APIDOC ## func NewCDict(dict []byte) (*CDict, error) ### Description Creates a new CDict from the given byte slice. Call Release when the returned dict is no longer used. ### Parameters - **dict** ([]byte) - The dictionary data. ### Returns - ***CDict** - The created compression dictionary. - **error** - An error if creation fails. ``` -------------------------------- ### StreamCompressDict Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to compress an io.Reader into an io.Writer using a dictionary. ```go func StreamCompressDict(dst io.Writer, src io.Reader, cd *CDict) error ``` -------------------------------- ### NewReader Source: https://pkg.go.dev/github.com/valyala/gozstd Returns a new zstd reader reading compressed data from an io.Reader. ```APIDOC ## func NewReader(r io.Reader) *Reader ### Description Returns a new zstd reader reading compressed data from r. Call Release when the Reader is no longer needed. ### Parameters - **r** (io.Reader) - Required - The source reader. ``` -------------------------------- ### Write Compressed Data Source: https://pkg.go.dev/github.com/valyala/gozstd Writes data to the compressor. Note that Flush or Close must be called to propagate data to the underlying writer. ```go func (zw *Writer) Write(p []byte) (int, error) ``` -------------------------------- ### StreamCompress Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to compress an io.Reader into an io.Writer. ```go func StreamCompress(dst io.Writer, src io.Reader) error ``` -------------------------------- ### Reset Writer Parameters Source: https://pkg.go.dev/github.com/valyala/gozstd Resets the writer to target a new io.Writer with specific compression parameters. ```go func (zw *Writer) ResetWriterParams(w io.Writer, params *WriterParams) ``` -------------------------------- ### Create new Writer with CDict Source: https://pkg.go.dev/github.com/valyala/gozstd Returns a new zstd writer using the specified CDict. Must be closed with Close to finalize the stream. ```go func NewWriterDict(w io.Writer, cd *CDict) *Writer ``` -------------------------------- ### Close Reader Source: https://pkg.go.dev/github.com/valyala/gozstd Alias for Release to implement the io.ReadCloser interface. ```go func (zr *Reader) Close() error ``` -------------------------------- ### func (*Writer) Write Source: https://pkg.go.dev/github.com/valyala/gozstd Writes data to the compressor. Note that this does not flush data immediately. ```APIDOC ## func (*Writer) Write ### Description Write writes p to zw. Write doesn't flush the compressed data to the underlying writer due to performance reasons. Call Flush or Close when the compressed data must propagate to the underlying writer. ### Signature `func (zw *Writer) Write(p []byte) (int, error)` ``` -------------------------------- ### Compress Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to compress a byte slice. ```go func Compress(dst, src []byte) []byte ``` -------------------------------- ### NewWriter Source: https://pkg.go.dev/github.com/valyala/gozstd Returns a new zstd writer writing compressed data to an io.Writer. ```APIDOC ## func NewWriter(w io.Writer) *Writer ### Description Returns a new zstd writer writing compressed data to w. The returned writer must be closed with Close call in order to finalize the compressed stream. Call Release when the Writer is no longer needed. ### Parameters - **w** (io.Writer) - Required - The destination writer. ``` -------------------------------- ### func Compress Source: https://pkg.go.dev/github.com/valyala/gozstd Appends compressed source data to a destination buffer. ```APIDOC ## func Compress(dst, src []byte) []byte ### Description Appends compressed src to dst and returns the result. ### Parameters - **dst** ([]byte) - The destination buffer. - **src** ([]byte) - The source data to compress. ### Returns - **[]byte** - The resulting buffer containing compressed data. ``` -------------------------------- ### NewCDictLevel Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Creates a new CDict from a byte slice with a specific compression level. ```go func NewCDictLevel(dict []byte, compressionLevel int) (*CDict, error) ``` -------------------------------- ### type WriterParams Source: https://pkg.go.dev/github.com/valyala/gozstd Configuration structure for defining compression behavior. ```APIDOC ## type WriterParams ### Description A WriterParams allows users to specify compression parameters. ### Fields - **CompressionLevel** (int) - Compression level. Special value 0 means 'default compression level'. - **WindowLog** (int) - Must be clamped between WindowLogMin and WindowLogMin32/64. Special value 0 means 'use default windowLog'. - **Dict** (*CDict) - Optional dictionary used for compression. ``` -------------------------------- ### NewDDict Source: https://pkg.go.dev/github.com/valyala/gozstd Creates a new decompression dictionary from the provided byte slice. ```APIDOC ## func NewDDict(dict []byte) (*DDict, error) ### Description Creates a new DDict from the given dict. Call Release when the returned dict is no longer needed. ### Parameters - **dict** ([]byte) - Required - The dictionary data. ``` -------------------------------- ### Decompress data Source: https://pkg.go.dev/github.com/valyala/gozstd Use the Decompress function to restore compressed data. ```go data, err := Decompress(nil, compressedData) ``` -------------------------------- ### StreamCompressLevel Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to compress an io.Reader into an io.Writer with a specific level. ```go func StreamCompressLevel(dst io.Writer, src io.Reader, compressionLevel int) error ``` -------------------------------- ### Define Default Compression Level Source: https://pkg.go.dev/github.com/valyala/gozstd Constant representing the default compression level used by the library. ```go const DefaultCompressionLevel = 3 // Obtained from ZSTD_CLEVEL_DEFAULT. ``` -------------------------------- ### StreamDecompressDict Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to decompress an io.Reader into an io.Writer using a dictionary. ```go func StreamDecompressDict(dst io.Writer, src io.Reader, dd *DDict) error ``` -------------------------------- ### Write Reader data to Writer Source: https://pkg.go.dev/github.com/valyala/gozstd Writes all data from the reader to the provided io.Writer and returns the number of bytes written. ```go func (zr *Reader) WriteTo(w io.Writer) (int64, error) ``` -------------------------------- ### CompressLevel Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to compress a byte slice with a specific compression level. ```go func CompressLevel(dst, src []byte, compressionLevel int) []byte ``` -------------------------------- ### StreamDecompress Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to decompress an io.Reader into an io.Writer. ```go func StreamDecompress(dst io.Writer, src io.Reader) error ``` -------------------------------- ### NewCDict Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Creates a new CDict from a byte slice. ```go func NewCDict(dict []byte) (*CDict, error) ``` -------------------------------- ### Read from Reader Source: https://pkg.go.dev/github.com/valyala/gozstd Reads up to len(p) bytes from the zstd reader into the provided buffer. ```go func (zr *Reader) Read(p []byte) (int, error) ``` -------------------------------- ### DecompressDict Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to decompress a byte slice using a pre-built dictionary. ```go func DecompressDict(dst, src []byte, dd *DDict) ([]byte, error) ``` -------------------------------- ### DecompressDictLimited Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to decompress a byte slice with a dictionary and a size limit. ```go func DecompressDictLimited(dst, src []byte, dd *DDict, limit int) ([]byte, error) ``` -------------------------------- ### Reset Reader Source: https://pkg.go.dev/github.com/valyala/gozstd Resets the reader to read from a new source using the specified dictionary. ```go func (zr *Reader) Reset(r io.Reader, dd *DDict) ``` -------------------------------- ### Reset Writer Source: https://pkg.go.dev/github.com/valyala/gozstd Resets the writer to write to a new destination using the specified dictionary and compression level. ```go func (zw *Writer) Reset(w io.Writer, cd *CDict, compressionLevel int) ``` -------------------------------- ### DecompressLimited Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to decompress a byte slice with a size limit. ```go func DecompressLimited(dst, src []byte, limit int) ([]byte, error) ``` -------------------------------- ### Read from Reader into Writer Source: https://pkg.go.dev/github.com/valyala/gozstd Reads data from an io.Reader and writes it to the zstd writer. May require a call to Flush or Close to propagate data. ```go func (zw *Writer) ReadFrom(r io.Reader) (int64, error) ``` -------------------------------- ### Writer.Close Source: https://pkg.go.dev/github.com/valyala/gozstd Finalizes the compressed stream and flushes data to the underlying writer. ```APIDOC ## func (*Writer) Close() error ### Description Close finalizes the compressed stream and flushes all the compressed data to the underlying writer. It doesn't close the underlying writer passed to New* functions. ``` -------------------------------- ### Release Reader resources Source: https://pkg.go.dev/github.com/valyala/gozstd Releases all resources occupied by the reader. The reader cannot be used after calling this method. ```go func (zr *Reader) Release() ``` -------------------------------- ### Release Writer resources Source: https://pkg.go.dev/github.com/valyala/gozstd Releases all resources occupied by the writer. The writer cannot be used after calling this method. ```go func (zw *Writer) Release() ``` -------------------------------- ### Writer struct definition Source: https://pkg.go.dev/github.com/valyala/gozstd Implements a zstd writer for compressing data. ```go type Writer struct { // contains filtered or unexported fields } ``` -------------------------------- ### CDict Type Definition Source: https://pkg.go.dev/github.com/valyala/gozstd Represents a dictionary used for compression. ```go type CDict struct { // contains filtered or unexported fields } ``` -------------------------------- ### Reader.Read Source: https://pkg.go.dev/github.com/valyala/gozstd Reads decompressed data from the zstd reader. ```APIDOC ## func (*Reader) Read(p []byte) (int, error) ### Description Read reads up to len(p) bytes from zr to p. ### Parameters - **p** ([]byte) - Required - The buffer to read into. ``` -------------------------------- ### Decompress Function Signature Source: https://pkg.go.dev/github.com/valyala/gozstd Defines the function to decompress a byte slice. ```go func Decompress(dst, src []byte) ([]byte, error) ``` -------------------------------- ### Flush Writer Source: https://pkg.go.dev/github.com/valyala/gozstd Flushes remaining data from the writer to the underlying writer. ```go func (zw *Writer) Flush() error ``` -------------------------------- ### Reader struct definition Source: https://pkg.go.dev/github.com/valyala/gozstd Implements a zstd reader for decompressing data. ```go type Reader struct { // contains filtered or unexported fields } ``` -------------------------------- ### Release DDict resources Source: https://pkg.go.dev/github.com/valyala/gozstd Releases resources occupied by the DDict. The object cannot be used after calling this method. ```go func (dd *DDict) Release() ``` -------------------------------- ### DDict struct definition Source: https://pkg.go.dev/github.com/valyala/gozstd Represents a dictionary used for decompression. A single DDict instance can be reused across concurrent goroutines. ```go type DDict struct { // contains filtered or unexported fields } ``` -------------------------------- ### Release CDict resources Source: https://pkg.go.dev/github.com/valyala/gozstd Releases resources occupied by the CDict. The object cannot be used after calling this method. ```go func (cd *CDict) Release() ``` -------------------------------- ### func Decompress Source: https://pkg.go.dev/github.com/valyala/gozstd Appends decompressed source data to a destination buffer. ```APIDOC ## func Decompress(dst, src []byte) ([]byte, error) ### Description Appends decompressed src to dst and returns the result. ### Parameters - **dst** ([]byte) - The destination buffer. - **src** ([]byte) - The source data to decompress. ### Returns - **[]byte** - The resulting buffer containing decompressed data. - **error** - An error if decompression fails. ``` -------------------------------- ### Close Writer Source: https://pkg.go.dev/github.com/valyala/gozstd Finalizes the compressed stream and flushes data to the underlying writer. Does not close the underlying writer. ```go func (zw *Writer) Close() error ``` -------------------------------- ### func (*Writer) ResetWriterParams Source: https://pkg.go.dev/github.com/valyala/gozstd Resets the writer to target a new io.Writer with specific compression parameters. ```APIDOC ## func (*Writer) ResetWriterParams ### Description Resets zw to write to w using the given set of parameters. ### Signature `func (zw *Writer) ResetWriterParams(w io.Writer, params *WriterParams)` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.