Module: Base85::Ascii85
- Extended by:
- ModuleMethods
- Defined in:
- lib/base85/ascii85.rb
Overview
Ascii85 base85 encoding. This encoding uses ! to u ASCII characters to encode data. z is used to represent 32-bit 0 value. The encoded string is surrounded by <~ and ~> markers.
Constant Summary collapse
- BASE_ASCII_VALUE =
ASCII value for character !
"!".ord
- SPECIAL_Z =
Ascii85 defines
zas a special character true- START_MARKER =
ASCII85 start marker
"<~"- END_MARKER =
ASCII85 end marker
"~>"
Constants included from ModuleMethods
Class Method Summary collapse
-
.decode(data) ⇒ String
Decode data using Ascii85 encoding.
-
.decode_char(char) ⇒ Integer
Decode a character from Ascii85 and give its index in alphabet.
-
.encode(data) ⇒ String
Encode data using Ascii85 encoding.
-
.encode_value(value) ⇒ String
Encode a value (0..84 integer) to a Ascii85 character.
Methods included from ModuleMethods
Class Method Details
.decode(data) ⇒ String
Decode data using Ascii85 encoding
51 52 53 54 55 |
# File 'lib/base85/ascii85.rb', line 51 def self.decode(data) start = data.start_with?(START_MARKER) ? 2 : 0 stop = data.end_with?(END_MARKER) ? -3 : -1 super(data[start..stop]) end |
.decode_char(char) ⇒ Integer
Decode a character from Ascii85 and give its index in alphabet
38 39 40 41 42 43 44 45 |
# File 'lib/base85/ascii85.rb', line 38 def self.decode_char(char) case char when "!".."u" # rubocop:disable Lint/MixedCaseRange char.ord - BASE_ASCII_VALUE else raise DecodeError, "unknown character '#{char}'" end end |
.encode(data) ⇒ String
Encode data using Ascii85 encoding
30 31 32 |
# File 'lib/base85/ascii85.rb', line 30 def self.encode(data) "#{START_MARKER}#{super}#{END_MARKER}" end |
.encode_value(value) ⇒ String
Encode a value (0..84 integer) to a Ascii85 character
23 24 25 |
# File 'lib/base85/ascii85.rb', line 23 def self.encode_value(value) (BASE_ASCII_VALUE + value).chr end |