Documentation ¶
Index ¶
- Constants
- Variables
- func Compress(dst, src []byte) ([]byte, error)
- func CompressBound(srcSize int) int
- func CompressLevel(dst, src []byte, level int) ([]byte, error)
- func Decompress(dst, src []byte) ([]byte, error)
- func IsDstSizeTooSmallError(e error) bool
- func NewReader(r io.Reader) io.ReadCloser
- func NewReaderDict(r io.Reader, dict []byte) io.ReadCloser
- func TryReadFull(r io.Reader, buf []byte) (n int, err error)
- type ErrorCode
- type Writer
Constants ¶
const ( BestSpeed = 1 BestCompression = 20 DefaultCompression = 5 )
Defines best and standard values for zstd cli
Variables ¶
var ( // ErrEmptySlice is returned when there is nothing to compress ErrEmptySlice = errors.New("Bytes slice is empty") )
Functions ¶
func Compress ¶
Compress src into dst. If you have a buffer to use, you can pass it to prevent allocation. If it is too small, or if nil is passed, a new buffer will be allocated and returned.
func CompressBound ¶
CompressBound returns the worst case size needed for a destination buffer, which can be used to preallocate a destination buffer or select a previously allocated buffer from a pool. See zstd.h to mirror implementation of ZSTD_COMPRESSBOUND
func CompressLevel ¶
CompressLevel is the same as Compress but you can pass a compression level
func Decompress ¶
Decompress src into dst. If you have a buffer to use, you can pass it to prevent allocation. If it is too small, or if nil is passed, a new buffer will be allocated and returned.
func IsDstSizeTooSmallError ¶
IsDstSizeTooSmallError returns whether the error correspond to zstd standard sDstSizeTooSmall error
func NewReader ¶
func NewReader(r io.Reader) io.ReadCloser
NewReader creates a new io.ReadCloser. Reads from the returned ReadCloser read and decompress data from r. It is the caller's responsibility to call Close on the ReadCloser when done. If this is not done, underlying objects in the zstd library will not be freed.
func NewReaderDict ¶
func NewReaderDict(r io.Reader, dict []byte) io.ReadCloser
NewReaderDict is like NewReader but uses a preset dictionary. NewReaderDict ignores the dictionary if it is nil.
func TryReadFull ¶
TryReadFull reads buffer just as ReadFull does Here we expect that buffer may end and we do not return ErrUnexpectedEOF as ReadAtLeast does. We return errShortRead instead to distinguish short reads and failures. We cannot use ReadFull/ReadAtLeast because it masks Reader errors, such as network failures and causes panic instead of error.
Types ¶
type Writer ¶
type Writer struct { CompressionLevel int // contains filtered or unexported fields }
Writer is an io.WriteCloser that zstd-compresses its input.
func NewWriter ¶
NewWriter creates a new Writer with default compression options. Writes to the writer will be written in compressed form to w.
func NewWriterLevel ¶
NewWriterLevel is like NewWriter but specifies the compression level instead of assuming default compression.
The level can be DefaultCompression or any integer value between BestSpeed and BestCompression inclusive.
func NewWriterLevelDict ¶
NewWriterLevelDict is like NewWriterLevel but specifies a dictionary to compress with. If the dictionary is empty or nil it is ignored. The dictionary should not be modified until the writer is closed.