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

package zstd

import "github.com/DataDog/zstd"

Index

Constants

const (
	BestSpeed       = 1
	BestCompression = 20
)

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.

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 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.

Types

type ErrorCode

type ErrorCode int

ErrorCode is an error returned by the zstd library.

var (
	ErrGeneric                           ErrorCode = -1
	ErrPrefixUnknown                     ErrorCode = -2
	ErrVersionUnsupported                ErrorCode = -3
	ErrParameterUnknown                  ErrorCode = -4
	ErrFrameParameterUnsupported         ErrorCode = -5
	ErrFrameParameterUnsupportedBy32bits ErrorCode = -6
	ErrFrameParameterWindowTooLarge      ErrorCode = -7
	ErrCompressionParameterUnsupported   ErrorCode = -8
	ErrCompressionParameterOutOfBound    ErrorCode = -9
	ErrInitMissing                       ErrorCode = -10
	ErrMemoryAllocation                  ErrorCode = -11
	ErrStageWrong                        ErrorCode = -12
	ErrDstSizeTooSmall                   ErrorCode = -13
	ErrSrcSizeWrong                      ErrorCode = -14
	ErrCorruptionDetected                ErrorCode = -15
	ErrChecksumWrong                     ErrorCode = -16
	ErrTableLogTooLarge                  ErrorCode = -17
	ErrMaxSymbolValueTooLarge            ErrorCode = -18
	ErrMaxSymbolValueTooSmall            ErrorCode = -19
	ErrDictionaryCorrupted               ErrorCode = -20
	ErrDictionaryWrong                   ErrorCode = -21
	ErrDictionaryCreationFailed          ErrorCode = -22
	ErrFrameIndexTooLarge                ErrorCode = -23
	ErrSeekableIO                        ErrorCode = -24
	ErrMaxCode                           ErrorCode = -25
	ErrEmptySlice                                  = errors.New("Bytes slice is empty")

	DefaultCompression = 5
)

FIXME: this is very fragile, must map 1-to-1 with zstd's error_public.h. They have no problem with adding error codes, renumbering errors, etc.

func (ErrorCode) Error

func (e ErrorCode) Error() string

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

zstd.go zstd_stream.go

Version
v1.3.0
Published
Sep 7, 2017
Platform
linux/amd64
Imports
7 packages
Last checked
1 week ago

Tools for package owners.