lz4

package module
v0.0.0-...-c221822 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 4 Imported by: 7

README

go-lz4

GoDoc Build Status

go-lz4 is Go bindings for LZ4 compression library.

Usage

import "github.com/hungys/go-lz4"

Here are all the available APIs,

func CompressBound(size int) int
func CompressDefault(source, dest []byte) (int, error)
func CompressFast(source, dest []byte, acceleration int) (int, error)

func DecompressSafe(source, dest []byte) (int, error)
func DecompressFast(source, dest []byte, originalSize int) (int, error)

We also provide another sets of APIs for compressing or decompressing struct or slice. For struct, you should pass a pointer. But noted that for slice, you should pass slice itself, but not a pointer!

func CompressAnyDefault(source, dest interface{}, sourceSize, maxDestSize int) (int, error)
func CompressAnyFast(source, dest interface{}, sourceSize, maxDestSize, acceleration int) (int, error)

func DecompressAnySafe(source, dest interface{}, compressedSize, maxDecompressedSize int) (int, error)
func DecompressAnyFast(source, dest interface{}, originalSize int) (int, error)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressAnyDefault

func CompressAnyDefault(source, dest interface{}, sourceSize, maxDestSize int) (int, error)

CompressAnyDefault works the same as CompressDefault, but you can pass pointer of struct or slice as a buffer. Also, the size of buffer should be specified explicitly.

func CompressAnyFast

func CompressAnyFast(source, dest interface{}, sourceSize, maxDestSize, acceleration int) (int, error)

CompressAnyFast works the same as CompressFast, but you can pass pointer of struct or slice as a buffer. Also, the size of buffer should be specified explicitly.

func CompressBound

func CompressBound(size int) int

CompressBound returns the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible).

func CompressDefault

func CompressDefault(source, dest []byte) (int, error)

CompressDefault compresses buffer "source" into already allocated "dest" buffer. Compression is guaranteed to succeed if size of "dest" >= CompressBound(size of "src") The function returns the number of bytes written into buffer "dest". If the function cannot compress "source" into a more limited "dest" budget, compression stops immediately, and the function result is zero.

func CompressFast

func CompressFast(source, dest []byte, acceleration int) (int, error)

CompressFast works the same as CompressDefault, but allows to select an "acceleration" factor. The larger the acceleration value, the faster the algorithm, but also the lesser the compression. An acceleration value of "1" is the same as regular CompressDefault()

func DecompressAnyFast

func DecompressAnyFast(source, dest interface{}, originalSize int) (int, error)

DecompressAnyFast works the same as DecompressFast, but you can pass pointer of struct or slice as a buffer.

func DecompressAnySafe

func DecompressAnySafe(source, dest interface{}, compressedSize, maxDecompressedSize int) (int, error)

DecompressAnySafe works the same as DecompressSafe, but you can pass pointer of struct or slice as a buffer. Also, the size of buffer should be specified explicitly.

func DecompressFast

func DecompressFast(source, dest []byte, originalSize int) (int, error)

DecompressFast fully respect memory boundaries for properly formed compressed data. It is a bit faster than DecompressSafe. However, it does not provide any protection against intentionally modified data stream (malicious input).

func DecompressSafe

func DecompressSafe(source, dest []byte) (int, error)

DecompressSafe decompresses buffer "source" into already allocated "dest" buffer. The function returns the number of bytes written into buffer "dest". If destination buffer is not large enough, decoding will stop and output an error code (<0). If the source stream is detected malformed, the function will stop decoding and return a negative result.

Types

This section is empty.

Jump to

Keyboard shortcuts

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