libz

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 5 Imported by: 1

README

go-libz

A wasm2go-based cgo-free Go port of Sortix libz.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress

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

Compress compresses src into dst, returning a slice pointing to the compressed data. If dst is nil, the maximum possible compressed length is allocated. Otherwise, if dst is too short, an error is returned.

func Uncompress

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

Uncompress decompresses src into dst, returning a slice pointing to the decompressed data. If dst is too short, an error is returned.

Types

type DataType

type DataType int

DataType is a data type guessed by inflate.

const (
	Z_BINARY  DataType = 0
	Z_TEXT    DataType = 1
	Z_ASCII   DataType = Z_TEXT
	Z_UNKNOWN DataType = 2
)

type Error

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

Error wraps a libz error code.

func (*Error) As

func (e *Error) As(err any) bool

As converts the error to an ErrorCode.

func (*Error) Code

func (e *Error) Code() ErrorCode

Code returns the ErrorCode for the error.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(err error) bool

Is returns true if the error matches an ErrorCode.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying Go error, if any.

type ErrorCode

type ErrorCode int32

ErrorCode is a return status for the compression functions. Negative values are errors, positive value are for special but normal events.

When used as an error, Z_OK is returned as nil.

const (
	Z_OK            ErrorCode = 0
	Z_STREAM_END    ErrorCode = 1
	Z_NEED_DICT     ErrorCode = 2
	Z_ERRNO         ErrorCode = -1
	Z_STREAM_ERROR  ErrorCode = -2
	Z_DATA_ERROR    ErrorCode = -3
	Z_MEM_ERROR     ErrorCode = -4
	Z_BUF_ERROR     ErrorCode = -5
	Z_VERSION_ERROR ErrorCode = -6
)

func (ErrorCode) Error

func (c ErrorCode) Error() string

type FlushType

type FlushType int32

FlushType is a flush type.

const (
	Z_NO_FLUSH      FlushType = 0
	Z_PARTIAL_FLUSH FlushType = 1
	Z_SYNC_FLUSH    FlushType = 2
	Z_FULL_FLUSH    FlushType = 3
	Z_FINISH        FlushType = 4
	Z_BLOCK         FlushType = 5
	Z_TREES         FlushType = 6
)

type Level

type Level int32

Level is a compression level.

Note that this doesn't match the levels in compress/flate since [LevelNoCompression] is zero, and there's no equivalent for huffman-only.

const (
	Z_NO_COMPRESSION      Level = 0
	Z_BEST_SPEED          Level = 1
	Z_BEST_COMPRESSION    Level = 9
	Z_DEFAULT_COMPRESSION Level = -1
)

type Strategy

type Strategy int32

Strategy is a compression strategy.

const (
	Z_FILTERED         Strategy = 1
	Z_HUFFMAN_ONLY     Strategy = 2
	Z_RLE              Strategy = 3
	Z_FIXED            Strategy = 4
	Z_DEFAULT_STRATEGY Strategy = 0
)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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