Module: Base85

Defined in:
lib/base85.rb,
lib/base85/cli.rb,
lib/base85/z85.rb,
lib/base85/ascii85.rb,
lib/base85/rfc1924.rb,
lib/base85/version.rb,
lib/base85/standard.rb,
lib/base85/module_methods.rb

Overview

Provide methods to encode/decode Base85 formatted data

Author:

  • sd77

Defined Under Namespace

Modules: Ascii85, ModuleMethods, Rfc1924, Standard, Z85 Classes: CLI, DecodeError, Error, UnknownAlphabetError

Constant Summary collapse

SUPPORTED_ALPHABETS =

Supported Base85 alphabets

i[standard ascii85 z85 rfc1924].freeze
VERSION =

Base85 gem version

"0.3.0"

Class Method Summary collapse

Class Method Details

.decode(data, alphabet: :standard) ⇒ String

Decode data using given alphabet

Parameters:

  • data (String)

    data to decode

  • alphabet (:standard, :ascii85, :z85, :rfc1924) (defaults to: :standard)

    alphabet to use to decode

Returns:

  • (String)

    decoded string



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/base85.rb', line 59

def self.decode(data, alphabet: :standard)
  case alphabet
  when :standard
    Standard.decode(data)
  when :ascii85
    Ascii85.decode(data)
  when :z85
    Z85.decode(data)
  when :rfc1924
    Rfc1924.decode(data)
  else
    raise UnknownAlphabetError.new(alphabet)
  end
end

.encode(data, alphabet: :standard) ⇒ String

Encode data using given alphabet

Parameters:

  • data (String)

    data to encode

  • alphabet (:standard, :ascii85, :z85, :rfc1924) (defaults to: :standard)

    alphabet to use to encode

Returns:

  • (String)

    encoded string



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/base85.rb', line 40

def self.encode(data, alphabet: :standard)
  case alphabet
  when :standard
    Standard.encode(data)
  when :ascii85
    Ascii85.encode(data)
  when :z85
    Z85.encode(data)
  when :rfc1924
    Rfc1924.encode(data)
  else
    raise UnknownAlphabetError.new(alphabet)
  end
end