Documentation
¶
Overview ¶
Package lzfse provides Go bindings for the lzfse compression library (https://github.com/lzfse/lzfse) that require no cgo.
The native code ships as a small shared library that this package loads and calls through github.com/ebitengine/purego, so binaries build and run with CGO_ENABLED=0. By default the package uses an embedded copy of the shared library for the current platform, extracted to the user cache directory on first use. SetLibraryPath or the LZFSE_LIBRARY_PATH environment variable can point at a different shared library instead.
The API mirrors github.com/blacktop/lzfse-cgo:
out, err := lzfse.EncodeBuffer(src) src2, err := lzfse.DecodeBuffer(out)
All functions are safe for concurrent use.
Index ¶
- Constants
- Variables
- func DecodeBuffer(src []byte) ([]byte, error)
- func DecodeBufferInto(src, dst []byte) (int, error)
- func DecodeLZVNBuffer(src, dst []byte) (int, error)
- func DecodeScratchSize() (int, error)
- func DecodeZBMBuffer(src, dst []byte) (int, error)
- func EncodeBuffer(src []byte) ([]byte, error)
- func EncodeBufferInto(src, dst []byte) (int, error)
- func EncodeLZVNBuffer(src, dst []byte) (int, error)
- func EncodeScratchSize() (int, error)
- func EncodeZBMBuffer(src, dst []byte) (int, error)
- func SetLibraryPath(path string) error
- type Library
- func (lib *Library) DecodeBuffer(src []byte) ([]byte, error)
- func (lib *Library) DecodeBufferInto(src, dst []byte) (int, error)
- func (lib *Library) DecodeLZVNBuffer(src, dst []byte) int
- func (lib *Library) DecodeScratchSize() int
- func (lib *Library) DecodeZBMBuffer(src, dst []byte) int
- func (lib *Library) EncodeBuffer(src []byte) ([]byte, error)
- func (lib *Library) EncodeBufferInto(src, dst []byte) (int, error)
- func (lib *Library) EncodeLZVNBuffer(src, dst []byte) int
- func (lib *Library) EncodeScratchSize() int
- func (lib *Library) EncodeZBMBuffer(src, dst []byte) int
- func (lib *Library) LZVNEncodeScratchSize() int
Constants ¶
const Version = "1.0.0"
Version of the vendored lzfse C sources.
Variables ¶
var ( // ErrShortBuffer is returned when the destination buffer cannot hold the // complete result. Compress with a buffer of at least // cap(src)+cap(src)/2+1024 bytes (what EncodeBuffer allocates), and // decompress into a buffer at least as large as the original input. ErrShortBuffer = errors.New("lzfse: destination buffer is too short") // ErrDecompress is returned when the native decoder rejects the input. ErrDecompress = errors.New("lzfse: decompression failed") )
var ErrUnsupported = errors.New("lzfse: unsupported platform")
ErrUnsupported is returned on platforms where the package cannot call the native library.
Functions ¶
func DecodeBuffer ¶
DecodeBuffer decompresses LZFSE-encoded src into a newly allocated buffer, returning the decompressed bytes.
func DecodeBufferInto ¶
DecodeBufferInto decompresses LZFSE-encoded src into dst, returning the number of bytes written. It returns ErrShortBuffer if dst is too small.
func DecodeLZVNBuffer ¶
DecodeLZVNBuffer decompresses LZVN-encoded src into dst, returning the number of bytes written, or 0 on error or if dst is too small.
func DecodeScratchSize ¶
DecodeScratchSize returns the required scratch buffer size to decompress using LZFSE.
func DecodeZBMBuffer ¶
DecodeZBMBuffer decompresses LZBITMAP-encoded src into dst, returning the number of bytes written, or 0 on error or if dst is too small.
func EncodeBuffer ¶
EncodeBuffer compresses src using LZFSE into a newly allocated buffer, returning the compressed bytes.
func EncodeBufferInto ¶
EncodeBufferInto compresses src into dst and returns the number of bytes written. It returns ErrShortBuffer if dst is too small.
func EncodeLZVNBuffer ¶
EncodeLZVNBuffer compresses src using the LZVN block format into dst, returning the number of bytes written, or 0 if dst is too small.
func EncodeScratchSize ¶
EncodeScratchSize returns the required scratch buffer size to compress using LZFSE.
func EncodeZBMBuffer ¶
EncodeZBMBuffer compresses src using the LZBITMAP container format into dst, returning the number of bytes written, or 0 on error or if dst is too small.
func SetLibraryPath ¶
SetLibraryPath sets the file path of the native lzfse library used by the package-level functions, bypassing the default search. It must be called before the first compression or decompression call.
Types ¶
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
Library is a loaded native lzfse library. The default Library is loaded lazily on first use; all package-level functions use it.
func DefaultLibrary ¶
DefaultLibrary returns the process-wide library used by the package-level functions, loading it on first use. The location is decided by SetLibraryPath, then the search described in the package docs.
func NewLibrary ¶
NewLibrary loads the native lzfse library from path. The returned library stays loaded for the lifetime of the process.
func (*Library) DecodeBuffer ¶
DecodeBuffer decompresses LZFSE-encoded src into a newly allocated buffer, returning the decompressed bytes.
func (*Library) DecodeBufferInto ¶
DecodeBufferInto decompresses LZFSE-encoded src into dst, returning the number of bytes written. It returns ErrShortBuffer if dst is too small.
func (*Library) DecodeLZVNBuffer ¶
DecodeLZVNBuffer decompresses LZVN-encoded src into dst, returning the number of bytes written, or 0 on error or if dst is too small.
func (*Library) DecodeScratchSize ¶
DecodeScratchSize returns the required scratch buffer size to decompress using LZFSE. It is lzfse_decode_scratch_size.
func (*Library) DecodeZBMBuffer ¶
DecodeZBMBuffer decompresses LZBITMAP-encoded src into dst, returning the number of bytes written, or 0 on error or if dst is too small.
func (*Library) EncodeBuffer ¶
EncodeBuffer compresses src using LZFSE into a newly allocated buffer, returning the compressed bytes.
func (*Library) EncodeBufferInto ¶
EncodeBufferInto compresses src into dst and returns the number of bytes written. It returns ErrShortBuffer if dst is too small. The encoder adapts its block layout to the space available, so a slightly undersized dst may still yield a valid (different) encoding; only when the output cannot fit at all does it fail.
func (*Library) EncodeLZVNBuffer ¶
EncodeLZVNBuffer compresses src using the LZVN block format into dst, returning the number of bytes written, or 0 if dst is too small.
func (*Library) EncodeScratchSize ¶
EncodeScratchSize returns the required scratch buffer size to compress using LZFSE. It is lzfse_encode_scratch_size.
func (*Library) EncodeZBMBuffer ¶
EncodeZBMBuffer compresses src using the LZBITMAP container format into dst, returning the number of bytes written, or 0 on error or if dst is too small.
func (*Library) LZVNEncodeScratchSize ¶
LZVNEncodeScratchSize returns the scratch size required by EncodeLZVNBuffer.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
demo
command
Command demo shows the lzfse package: it compresses and decompresses a file with LZFSE and prints the sizes.
|
Command demo shows the lzfse package: it compresses and decompresses a file with LZFSE and prints the sizes. |
|
internal
|
|
|
libbuild
command
Command libbuild builds the native lzfse shared libraries that this package embeds under libs/, using the vendored C sources in native/.
|
Command libbuild builds the native lzfse shared libraries that this package embeds under libs/, using the vendored C sources in native/. |