altivi / lz_string Goto Github PK
View Code? Open in Web Editor NEWRuby implementation of LZ-String compression algorithm
License: MIT License
Ruby implementation of LZ-String compression algorithm
License: MIT License
The javascript version (1.5.0 from npm) handles unicode characters in the input string:
> lz=require('lz-string')
> lz.compressToBase64('ö')
'G9A='
> lz.decompressFromBase64(lz.compressToBase64('ö'))
'ö'
> lz.decompressFromBase64(lz.compressToBase64('\u2764'))
'❤'
> lz.decompressFromBase64(lz.compressToBase64('\u{1f3b6}'))
'🎶'
Doing the same in the ruby version (0.2.0) fails:
[10] pry(main)> LZString::Base64.decompress LZString::Base64.compress "ö"
=> "\xF6"
[11] pry(main)> LZString::Base64.decompress LZString::Base64.compress "\u2764"
=> nil
LZString::Base64.decompress LZString::Base64.compress "\u{1f3b6}"
=> nil
In addition, for the last emoji, compress returns different values (jwbjb9o=
from javascript, m3PQ
from ruby). Seems like the ruby version expects latin1 on input, fails miserably on characters outside of it, and returns a string with wrong encoding (Binary instead of ISO8859_1)
3: from decode.rb:1:in `<main>'
2: from decode.rb:1:in `require'
1: from /Users/something/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/lz_string-0.1.1/lib/lz_string.rb:1:in `<top (required)>'
/Users/something/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/lz_string-0.1.1/lib/lz_string.rb:1:in `require': cannot load such file -- pry (LoadError)```
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.