Skip to content

Update README.md - #279

Open
altivi wants to merge 1 commit into
pieroxy:masterfrom
altivi:ruby-lz-string
Open

altivi wants to merge 1 commit into
pieroxy:masterfrom
altivi:ruby-lz-string

Conversation

@altivi

@altivi altivi commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Hi! I made the Ruby gem lz_string.

Pull request 274 struck it through in the README as "only partial support" and listed
lzstring-ruby as the complete version. That was right about
lz_string 0.3.0: emoji did not work in it. Two things have changed since then.

lz_string 1.0.0 passes your test suite

lz_string 1.0.0 passes test/test.sh, 70 of 70 checks:

$ gem install lz_string
$ cd test
$ cat > profiles/lz_string.sh <<'EOF'
optDescription="Running using the lz_string Ruby gem"
optCommand=lz_string
optDecompress="-d"
optEncoder="-e"
optEncoders="base64,encodeduri,raw,uint8array,utf16"
optOutput="-o"
optQuiet="-q"
EOF
$ ./test.sh lz_string

It has every function of lz-string 2 (custom too) and a command line tool with the same options.
I also compared it with lz-string 2 on 20,000 random strings (all of Unicode: emoji, lone surrogates,
__proto__), 343 long ones (up to 200,000 characters) and 40,000 broken inputs, in all 6 encodings:
410,066 checks, 0 differences. With 1.5.0 it is the same for all real data.
Its CI runs your test.sh on every push.

lzstring-ruby 1.0.0 gives other results than lz-string, and loses data

lz-string lzstring-ruby 1.0.0
compressToBase64("🎶") "jwbjb9o=" "m3PQ"
decompressFromBase64("jwbjb9o=") "🎶" "??"
decompress of what lz-string gives for "👨‍👩‍👧‍👦" "👨‍👩‍👧‍👦" "??‍??‍??‍??"
compress, then decompress "I ❤ 🎶 music" (in lzstring-ruby itself) "I ❤ music"
compressToBase64("ö") "G9A=" "m8AQ"
compressToBase64("") "Q===" ""

The causes are in its source:
it reads Ruby characters
(code points), not UTF-16 code units, so an emoji loses its top bits;
it writes characters 128 to 255 with 16 bits
(< 128 where lz-string has < 256); and
it turns surrogates into "?"
when it decompresses.

With test.sh and its own lzstring command, it passes 13 of 70 checks, and 0 of the 35 compress checks
(with --no-verify: 23 of 70).
Part of this comes from its command line tool, which reads and writes UTF-8, while your tool and the test data use
UTF-16 code units. The table above shows the problems in the compression itself.

./test.sh output for lzstring-ruby 1.0.0
TestData    Encoding   Compress Decompress
all_ascii   base64         ✘        ✔
            encodeduri     ✘        ✔
            raw            ‼        ‼
            uint8array     ‼        ‼
            utf16          ✘        ‼
all_utf16   base64         ‼        ‼
            encodeduri     ‼        ‼
            raw            ‼        ‼
            uint8array     ‼        ‼
            utf16          ‼        ‼
hello_world base64         ✘        ✔
            encodeduri     ✘        ✔
            raw            ✘        ‼
            uint8array     ✘        ✔
            utf16          ✘        ‼
lorem_ipsum base64         ✘        ✔
            encodeduri     ✘        ✔
            raw            ‼        ‼
            uint8array     ‼        ‼
            utf16          ✘        ‼
pi          base64         ✘        ✔
            encodeduri     ✘        ✔
            raw            ‼        ‼
            uint8array     ‼        ‼
            utf16          ✘        ‼
repeated    base64         ✘        ✔
            encodeduri     ✘        ✔
            raw            ‼        ‼
            uint8array     ‼        ‼
            utf16          ✘        ‼
tattoo      base64         ✘        ✔
            encodeduri     ✘        ✔
            raw            ‼        ‼
            uint8array     ‼        ‼
            utf16          ✘        ‼

✘: the data doesn't match. ‼: the command failed. Decompress only reads back the tool's own output.

To see it yourself:

$ gem install lzstring-ruby
$ ruby -e 'require "lzstring"; p LZString.compress_to_base64("🎶"), LZString.decompress_from_base64("jwbjb9o=")'
"m3PQ"
"??"

This pull request

  • lists lz_string again, without the strike-through;
  • removes lzstring-ruby, because of the results above.

Thank you for lz-string and for the test suite. It made this easy to check.

@altivi

altivi commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@pieroxy @Rycochet please check.

@altivi altivi changed the title docs: list lz_string again, remove lzstring-ruby Update README.md Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant