Module: HTTPX::Base64

Defined in:
lib/httpx/base64.rb

Overview

require “base64” will not be a default gem after ruby 3.4.0

Class Method Summary collapse

Class Method Details

.decode64(str) ⇒ Object



11
12
13
# File 'lib/httpx/base64.rb', line 11

def decode64(str)
  str.unpack1("m")
end

.strict_encode64(bin) ⇒ Object



15
16
17
# File 'lib/httpx/base64.rb', line 15

def strict_encode64(bin)
  [bin].pack("m0")
end

.urlsafe_encode64(bin, padding: true) ⇒ Object



19
20
21
22
23
24
# File 'lib/httpx/base64.rb', line 19

def urlsafe_encode64(bin, padding: true)
  str = strict_encode64(bin)
  str.chomp!("==") or str.chomp!("=") unless padding
  str.tr!("+/", "-_")
  str
end