compressor

package
v0.0.5-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBufferSize = 32 * 1024
)
View Source
const (
	TypeNone = 0
)
View Source
const (
	TypeZlib = 2
)

Variables

View Source
var GzipOpts gzipOpts
View Source
var ZlibOpts zlibOpts

Functions

func GetName

func GetName(compressType uint16) string

func NewBufferCompressor

func NewBufferCompressor(size int) *bufferCompressor

func NewGzipCompressor

func NewGzipCompressor(opts ...GzipOpt) *gzipCompressor

func NewZlibCompressor

func NewZlibCompressor(opts ...ZlibOpt) *zlibCompressor

func RegisterType

func RegisterType(compressType uint16, compressName string) bool

Types

type Compressor

type Compressor interface {
	// 压缩类型
	Type() Type

	// 将srcReader的数据压缩至dstWriter
	// 参数dstWriter:压缩数据写入的writer
	// 参数srcReader:原始数据读取的reader
	// 返回before:原始数据大小
	// 返回after:压缩后数据大小
	// 返回err:发生错误时返回,无错误返回nil
	Compress(dstWriter io.Writer, srcReader io.Reader) (before int64, after int64, err error)

	// 将srcReader的数据解压至dstWriter
	// 参数dstWriter:解压数据写入的writer
	// 参数srcReader:压缩数据读取的reader
	// 返回before:压缩数据大小
	// 返回after:解压后数据大小
	// 返回err:发生错误时返回,无错误返回nil
	Decompress(dstWriter io.Writer, srcReader io.Reader) (before int64, after int64, err error)
}

type GzipCompressLevel

type GzipCompressLevel int
const (
	TypeGzip = 1

	NoCompression      GzipCompressLevel = gzip.NoCompression
	BestSpeed          GzipCompressLevel = gzip.BestSpeed
	BestCompression    GzipCompressLevel = gzip.BestCompression
	DefaultCompression GzipCompressLevel = gzip.DefaultCompression
	HuffmanOnly        GzipCompressLevel = gzip.HuffmanOnly
)

type GzipOpt

type GzipOpt func(c *gzipCompressor)

type SizeReader

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

func NewSizeReader

func NewSizeReader(r io.Reader) *SizeReader

func (*SizeReader) Close

func (r *SizeReader) Close() error

func (*SizeReader) Read

func (r *SizeReader) Read(d []byte) (int, error)

func (*SizeReader) Size

func (r *SizeReader) Size() int64

type SizeWriter

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

func NewSizeWriter

func NewSizeWriter(w io.Writer) *SizeWriter

func (*SizeWriter) Close

func (w *SizeWriter) Close() error

func (*SizeWriter) Size

func (w *SizeWriter) Size() int64

func (*SizeWriter) Write

func (w *SizeWriter) Write(d []byte) (int, error)

type Type

type Type uint16

func ToType

func ToType(t uint16) Type

func (Type) Value

func (t Type) Value() uint16

type ZlibOpt

type ZlibOpt func(c *zlibCompressor)

Jump to

Keyboard shortcuts

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