zstd – github.com/DataDog/zstd Index | Files

package zstd

import "github.com/DataDog/zstd"

Index

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

func Compress(dst, src []byte) ([]byte, error)

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

func CompressBound(srcSize int) int

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

func CompressLevel(dst, src []byte, level int) ([]byte, error)

CompressLevel is the same as Compress but you can pass a compression level

func Decompress

func Decompress(dst, src []byte) ([]byte, error)

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

func IsDstSizeTooSmallError(e error) bool

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

func TryReadFull(r io.Reader, buf []byte) (n int, err error)

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 ErrorCode

type ErrorCode int

ErrorCode is an error returned by the zstd library.

func (ErrorCode) Error

func (e ErrorCode) Error() string

Error returns the error string given by zstd

type Writer

type Writer struct {
	CompressionLevel int
	// contains filtered or unexported fields
}

Writer is an io.WriteCloser that zstd-compresses its input.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a new Writer with default compression options. Writes to the writer will be written in compressed form to w.

func NewWriterLevel

func NewWriterLevel(w io.Writer, level int) *Writer

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

func NewWriterLevelDict(w io.Writer, level int, dict []byte) *Writer

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.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the Writer, flushing any unwritten data to the underlying io.Writer and freeing objects, but does not close the underlying io.Writer.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write writes a compressed form of p to the underlying io.Writer.

Source Files

errors.go zstd.go zstd_stream.go

Version
v1.4.1
Published
Jul 23, 2019
Platform
js/wasm
Imports
8 packages
Last checked
now

Tools for package owners.