Documentation
¶
Overview ¶
Package unishox2 provides Go bindings for the Unishox2 compression algorithm.
Unishox2 is a lossless compression algorithm optimized for short strings and Unicode text. It achieves high compression ratios while maintaining fast compression and decompression speeds.
Basic usage:
// Compress a string
compressed, err := unishox2.CompressSimple("Hello, World!")
if err != nil {
log.Fatal(err)
}
// Decompress
decompressed, err := unishox2.DecompressSimple(compressed)
if err != nil {
log.Fatal(err)
}
Presets:
The package provides several presets optimized for different types of data:
- PresetDefault: General purpose (default)
- PresetAlphaOnly: Alphabetic text only
- PresetAlphaNumOnly: Alphanumeric text only
- PresetURL: URLs
- PresetJSON: JSON data
- PresetXML: XML data
- PresetHTML: HTML data
Example with preset:
compressed, err := unishox2.Compress("Hello", unishox2.PresetJSON)
Index ¶
- Variables
- func Compress(data []byte, preset Preset) ([]byte, error)
- func CompressSimple(data []byte) ([]byte, error)
- func CompressSimpleString(s string) ([]byte, error)
- func CompressString(s string, preset Preset) ([]byte, error)
- func Decompress(data []byte, preset Preset) ([]byte, error)
- func DecompressSimple(data []byte) ([]byte, error)
- func DecompressSimpleString(data []byte) (string, error)
- func DecompressString(data []byte, preset Preset) (string, error)
- type Preset
Constants ¶
This section is empty.
Variables ¶
var ( ErrCompressionFailed = errors.New("unishox2: compression failed") ErrDecompressionFailed = errors.New("unishox2: decompression failed") ErrBufferTooSmall = errors.New("unishox2: output buffer too small") )
Error definitions.
Functions ¶
func Compress ¶
Compress compresses data using the specified preset. Returns the compressed data or an error if compression fails.
func CompressSimple ¶
CompressSimple compresses data using the default preset. Returns the compressed data or an error if compression fails.
func CompressSimpleString ¶
CompressSimpleString compresses a string using the default preset. Returns the compressed data or an error if compression fails.
func CompressString ¶
CompressString compresses a string using the specified preset. Returns the compressed data or an error if compression fails.
func Decompress ¶
Decompress decompresses data using the specified preset. Returns the decompressed data or an error if decompression fails.
func DecompressSimple ¶
DecompressSimple decompresses data using the default preset. Returns the decompressed data or an error if decompression fails.
func DecompressSimpleString ¶
DecompressSimpleString decompresses data and returns a string. Returns the decompressed string or an error if decompression fails.
Types ¶
type Preset ¶
type Preset int
Preset represents a compression preset configuration.
const ( PresetDefault Preset = 0 // Optimum - favors all including JSON, XML, URL and HTML PresetAlphaOnly Preset = 1 // Alphabets [a-z], [A-Z] and space only PresetAlphaNumOnly Preset = 2 // Alphanumeric [a-z], [A-Z], [0-9] and space only PresetAlphaNumSymOnly Preset = 3 // Alphanumeric and symbols only PresetAlphaNumSymOnlyTxt Preset = 4 // Alphanumeric and symbols only (Favor English text) PresetFavorAlpha Preset = 5 // Favor Alphabets PresetFavorDict Preset = 6 // Favor Dictionary coding PresetFavorSym Preset = 7 // Favor Symbols PresetFavorUmlaut Preset = 8 // Favor Umlaut PresetNoDict Preset = 9 // No dictionary PresetNoUni Preset = 10 // No Unicode PresetNoUniFavorText Preset = 11 // No Unicode, favour English text PresetURL Preset = 12 // Favor URLs PresetJSON Preset = 13 // Favor JSON PresetJSONNoUni Preset = 14 // Favor JSON (No Unicode) PresetXML Preset = 15 // Favor XML PresetHTML Preset = 16 // Favor HTML )
Preset constants for different data types.