Module: ActiveSupport::Base64
- Defined in:
- activesupport/lib/active_support/base64.rb
Overview
Base64 provides utility methods for encoding and de-coding binary data using a base 64 representation. A base 64 representation of binary data consists entirely of printable US-ASCII characters. The Base64 module is included in Ruby 1.8, but has been removed in Ruby 1.9.
Class Method Summary (collapse)
-
+ (Object) decode64(data)
Decodes a base 64 encoded string to its original representation.
-
+ (Object) encode64(data)
Encodes a string to its base 64 representation.
-
+ (Object) encode64s(value)
Encodes the value as base64 without the newline breaks.
Class Method Details
+ (Object) decode64(data)
Decodes a base 64 encoded string to its original representation.
ActiveSupport::Base64.decode64("T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==") # => "Original unencoded string"
28 29 30 |
# File 'activesupport/lib/active_support/base64.rb', line 28 def self.decode64(data) data.unpack("m").first end |
+ (Object) encode64(data)
Encodes a string to its base 64 representation. Each 60 characters of output is separated by a newline character.
ActiveSupport::Base64.encode64("Original unencoded string") # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==\n"
20 21 22 |
# File 'activesupport/lib/active_support/base64.rb', line 20 def self.encode64(data) [data].pack("m") end |
+ (Object) encode64s(value)
Encodes the value as base64 without the newline breaks. This makes the base64 encoding readily usable as URL parameters or memcache keys without further processing.
ActiveSupport::Base64.encode64s("Original unencoded string") # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw=="
39 40 41 |
# File 'activesupport/lib/active_support/base64.rb', line 39 def Base64.encode64s(value) encode64(value).gsub(/\n/, '') end |