Class: LZString::Base64
- Inherits:
-
Object
- Object
- LZString::Base64
- Defined in:
- lib/lz_string/base64.rb
Overview
Base64 compressing algorithm.
Constant Summary collapse
- KEY_STR_BASE64 =
Base64 alphabet.
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
Class Method Summary collapse
Class Method Details
.compress(input) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lz_string/base64.rb', line 8 def self.compress(input) return "" if input.nil? res = LZString::Base.compress(input, 6, lambda { |a| KEY_STR_BASE64[a] }) # To produce valid Base64 case (res.length % 4) when 0 then res when 1 then res + "===" when 2 then res + "==" when 3 then res + "=" end end |
.decompress(compressed) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lz_string/base64.rb', line 23 def self.decompress(compressed) return "" if compressed.nil? return nil if compressed == "" LZString::Base.decompress( compressed.length, 32, lambda { |index| get_base_value(KEY_STR_BASE64, compressed[index]) } ) end |