Module: Base64

Defined in:
lib/base64_backport.rb

Class Method Summary collapse

Class Method Details

.decode64(str) ⇒ Object



8
9
10
# File 'lib/base64_backport.rb', line 8

def decode64(str)
  str.unpack("m").first
end

.encode64(bin) ⇒ Object



4
5
6
# File 'lib/base64_backport.rb', line 4

def encode64(bin)
  [bin].pack("m")
end

.strict_decode64(str) ⇒ Object



16
17
18
# File 'lib/base64_backport.rb', line 16

def strict_decode64(str)
  decode64( str.gsub(/\n/, "") ).first
end

.strict_encode64(bin) ⇒ Object



12
13
14
# File 'lib/base64_backport.rb', line 12

def strict_encode64(bin)
  encode64(bin).gsub(/\n/, "")
end

.urlsafe_decode64(str) ⇒ Object



24
25
26
# File 'lib/base64_backport.rb', line 24

def urlsafe_decode64(str)
  strict_decode64(str.tr("-_", "+/"))
end

.urlsafe_encode64(bin) ⇒ Object



20
21
22
# File 'lib/base64_backport.rb', line 20

def urlsafe_encode64(bin)
  strict_encode64(bin).tr("+/", "-_")
end