Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Base64#decode64
decode64(str)
lib/base64.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/base64.rb, line 241
def decode64(str)
str.unpack1("m")
end
Returns a string containing the decoding of an RFC-2045-compliant Base64-encoded string str:
Example
s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n" Base64.decode64(s) # => "This is line 1\nThis is line 2\n"
Non-Base64 characters in str are ignored; see Encoding Character Set above: these include newline characters and characters - and /:
Example
Base64.decode64("\x00\n-_") # => ""
Padding in str (even if incorrect) is ignored:
Example
Base64.decode64("MDEyMzQ1Njc") # => "01234567" Base64.decode64("MDEyMzQ1Njc=") # => "01234567" Base64.decode64("MDEyMzQ1Njc==") # => "01234567"