Sha256: c608c5271babeedc28005a062831049ae46739de395283a9b262cb96cfc69e5f

Contents?: true

Size: 1.38 KB

Versions: 97

Compression:

Stored size: 1.38 KB

Contents

begin
  require 'base64'
rescue LoadError
end

module ActiveSupport
  if defined? ::Base64
    Base64 = ::Base64
  else
    # 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.
    module Base64
      # 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"
      def self.encode64(data)
        [data].pack("m")
      end

      # Decodes a base 64 encoded string to its original representation.
      #
      #  ActiveSupport::Base64.decode64("T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==")
      #  # => "Original unencoded string"
      def self.decode64(data)
        data.unpack("m").first
      end
    end
  end

  # 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=="
  def Base64.encode64s(value)
    encode64(value).gsub(/\n/, '')
  end
end

Version data entries

97 entries across 97 versions & 4 rubygems

Version Path
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/base64.rb
activesupport-3.1.12 lib/active_support/base64.rb
activesupport-3.1.11 lib/active_support/base64.rb
activesupport-3.0.20 lib/active_support/base64.rb
activesupport-3.1.10 lib/active_support/base64.rb
activesupport-3.0.19 lib/active_support/base64.rb
activesupport-3.1.9 lib/active_support/base64.rb
activesupport-3.0.18 lib/active_support/base64.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/base64.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/base64.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/base64.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/base64.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/base64.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/base64.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/base64.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/base64.rb
activesupport-3.1.8 lib/active_support/base64.rb
activesupport-3.0.17 lib/active_support/base64.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/base64.rb
activesupport-3.1.7 lib/active_support/base64.rb