lz_string

    Port of lz-string algorithm to MoonBit

    compression
    decompression
    lz-string
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    6 months ago
    Downloads
    16

    #sennenki/lz_string

    MoonBit port of the lz-string algorithm, aligned with upstream behavior in .repos/lz-string.

    #Features

    • Raw string compression/decompression
    • Base64 codec
    • UTF16-safe codec
    • URI component-safe codec
    • Custom dictionary codec
    • Uint8Array conversion and codec helpers

    #Public API

    • compress(s : String) -> String
    • decompress(s : String) -> String?
    • compress_to_base64(s : String) -> String
    • decompress_from_base64(s : String) -> String?
    • compress_to_utf16(s : String) -> String
    • decompress_from_utf16(s : String) -> String?
    • compress_to_encoded_uri_component(s : String) -> String
    • decompress_from_encoded_uri_component(s : String) -> String?
    • compress_to_custom(s : String, dict : String) -> String
    • decompress_from_custom(s : String, dict : String) -> String?
    • compress_to_uint8_array(s : String) -> Array[Byte]
    • decompress_from_uint8_array(bytes : Array[Byte]) -> String?
    • convert_to_uint8_array(s : String, force_even? : Bool = false) -> Array[Byte]
    • convert_from_uint8_array(bytes : Array[Byte]) -> String

    #Examples

    ///|
    test "raw round trip" {
    let input = "Hello MoonBit"
    let compressed = @lz_string.compress(input)
    assert_eq(@lz_string.decompress(compressed), Some(input))
    }

    ///|
    test "base64 round trip" {
    let input = "LZ String"
    let compressed = @lz_string.compress_to_base64(input)
    assert_eq(@lz_string.decompress_from_base64(compressed), Some(input))
    }

    ///|
    test "custom dictionary" {
    let dict = "0123456789ABCDEF"
    let input = "abcabcabc"
    let compressed = @lz_string.compress_to_custom(input, dict)
    assert_eq(@lz_string.decompress_from_custom(compressed, dict), Some(input))
    }

    #Notes

    • Empty compressed input returns None in decompress* APIs.
    • The implementation follows upstream code-unit-oriented behavior to preserve compatibility with JavaScript lz-string outputs.
    • Tests include dataset checks, golden vectors, edge cases, and full coverage.

    compress

    fn compress(uncompressed : String) -> String

    compress_to_base64

    fn compress_to_base64(input : String) -> String

    compress_to_custom

    fn compress_to_custom(uncompressed : String, dict : String) -> String

    compress_to_encoded_uri_component

    fn compress_to_encoded_uri_component(input : String) -> String

    compress_to_uint8_array

    fn compress_to_uint8_array(uncompressed : String) -> Array[Byte]

    compress_to_utf16

    fn compress_to_utf16(input : String) -> String

    convert_from_uint8_array

    fn convert_from_uint8_array(data : Array[Byte]) -> String

    convert_to_uint8_array

    fn convert_to_uint8_array(data : String, force_even? : Bool) -> Array[Byte]

    decompress

    fn decompress(compressed : String) -> String?

    decompress_from_base64

    fn decompress_from_base64(input : String) -> String?

    decompress_from_custom

    fn decompress_from_custom(compressed : String, dict : String) -> String?

    decompress_from_encoded_uri_component

    fn decompress_from_encoded_uri_component(input : String) -> String?

    decompress_from_uint8_array

    fn decompress_from_uint8_array(compressed : Array[Byte]) -> String?

    decompress_from_utf16

    fn decompress_from_utf16(compressed : String) -> String?

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io