Method: Base64.encode64

Defined in:
lib/base64.rb

.encode64(bin) ⇒ Object

Returns a string containing the RFC-2045-compliant Base64-encoding of bin.

Per RFC 2045, the returned string may contain the URL-unsafe characters + or /; see Encoding Character Set above:

Base64.encode64("\xFB\xEF\xBE") # => "++++\n"
Base64.encode64("\xFF\xFF\xFF") # => "////\n"

The returned string may include padding; see Padding above.

Base64.encode64('*') # => "Kg==\n"

The returned string ends with a newline character, and if sufficiently long will have one or more embedded newline characters; see Newlines above:

Base64.encode64('*') # => "Kg==\n"
Base64.encode64('*' * 46)
# => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq\nKg==\n"

The string to be encoded may itself contain newlines, which will be encoded as ordinary Base64:

Base64.encode64("\n\n\n") # => "CgoK\n"
s = "This is line 1\nThis is line 2\n"
Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"


219
220
221
# File 'lib/base64.rb', line 219

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