Module: Asciidoctor::Diagram::Base64
- Defined in:
- lib/asciidoctor-diagram/util/base64.rb
Class Method Summary collapse
Class Method Details
.urlsafe_decode(str) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/asciidoctor-diagram/util/base64.rb', line 11 def self.urlsafe_decode(str) # NOTE: RFC 4648 does say nothing about unpadded input, but says that # "the excess pad characters MAY also be ignored", so it is inferred that # unpadded input is also acceptable. if !str.end_with?("=") && str.length % 4 != 0 str = str.ljust((str.length + 3) & ~3, "=") str.tr!("-_", "+/") else str = str.tr("-_", "+/") end str.unpack1("m0") end |
.urlsafe_encode(bin, padding: true) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/asciidoctor-diagram/util/base64.rb', line 4 def self.urlsafe_encode(bin, padding: true) str = [bin].pack("m0") str.chomp!("==") or str.chomp!("=") unless padding str.tr!("+/", "-_") str end |