compressor

package
v0.0.0-...-1593278 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ZstdCompress

func ZstdCompress(in io.Reader, out io.Writer, opts ...zstd.EOption) error

Usa case: compress stream, large object only once This can be called concurrently Try ZstdCompressor for better efficiency if you need compress mutiple streams one by one

func ZstdCompressBytes

func ZstdCompressBytes(src, dst []byte) []byte

Use case: compress small blocks This can be called concurrently

func ZstdDecompress

func ZstdDecompress(in io.Reader, out io.Writer, opts ...zstd.DOption) error

Use case: decompress stream, large object only once This can be called concurrently Try ZstdDecompressor for better efficiency if you need decompress mutiple streams one by one

func ZstdDecompressBytes

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

Use case: decompress small blocks This can be called concurrently

Types

type CompressType

type CompressType string
const (
	CompressTypeZstd CompressType = "zstd"

	DefaultCompressAlgorithm CompressType = CompressTypeZstd
)

type Compressor

type Compressor interface {
	Compress(in io.Reader) error
	CompressBytes(src, dst []byte) []byte
	ResetWriter(out io.Writer)
	// Flush() error
	Close() error
	GetType() CompressType
}

type Decompressor

type Decompressor interface {
	Decompress(out io.Writer) error
	DecompressBytes(src, dst []byte) ([]byte, error)
	ResetReader(in io.Reader)
	Close()
	GetType() CompressType
}

type ZstdCompressor

type ZstdCompressor struct {
	// contains filtered or unexported fields
}

func NewZstdCompressor

func NewZstdCompressor(out io.Writer, opts ...zstd.EOption) (*ZstdCompressor, error)

For compressing small blocks, pass nil to the `out` parameter

func (*ZstdCompressor) Close

func (c *ZstdCompressor) Close() error

The compressor is still re-used after calling this

func (*ZstdCompressor) Compress

func (c *ZstdCompressor) Compress(in io.Reader) error

Use case: compress stream Call Close() to make sure the data is flushed to the underlying writer after the last Compress() call

func (*ZstdCompressor) CompressBytes

func (c *ZstdCompressor) CompressBytes(src []byte, dst []byte) []byte

Use case: compress small blocks This compresses the src bytes and appends it to the dst bytes, then return the result This can be called concurrently

func (*ZstdCompressor) GetType

func (c *ZstdCompressor) GetType() CompressType

func (*ZstdCompressor) ResetWriter

func (c *ZstdCompressor) ResetWriter(out io.Writer)

Reset the writer to reuse the compressor

type ZstdDecompressor

type ZstdDecompressor struct {
	// contains filtered or unexported fields
}

func NewZstdDecompressor

func NewZstdDecompressor(in io.Reader, opts ...zstd.DOption) (*ZstdDecompressor, error)

For compressing small blocks, pass nil to the `in` parameter

func (*ZstdDecompressor) Close

func (dec *ZstdDecompressor) Close()

NOTICE: not like compressor, the decompressor is not usable after calling this

func (*ZstdDecompressor) Decompress

func (dec *ZstdDecompressor) Decompress(out io.Writer) error

Usa case: decompress stream Write the decompressed data into `out`

func (*ZstdDecompressor) DecompressBytes

func (dec *ZstdDecompressor) DecompressBytes(src []byte, dst []byte) ([]byte, error)

Use case: decompress small blocks This decompresses the src bytes and appends it to the dst bytes, then return the result This can be called concurrently

func (*ZstdDecompressor) GetType

func (dec *ZstdDecompressor) GetType() CompressType

func (*ZstdDecompressor) ResetReader

func (dec *ZstdDecompressor) ResetReader(in io.Reader)

Reset the reader to reuse the decompressor

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL