File: base64.rb

package info (click to toggle)
ruby-sasl 0.0.3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 128 kB
  • sloc: ruby: 451; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 762 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# =XMPP4R - XMPP Library for Ruby
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
# Website::http://home.gna.org/xmpp4r/

begin
  require 'base64'
rescue LoadError
  ##
  # Ruby 1.9 has dropped the Base64 module,
  # this is a replacement
  #
  # We could replace all call by Array#pack('m')
  # and String#unpack('m'), but this module
  # improves readability.
  module Base64
    ##
    # Encode a String
    # data:: [String] Binary
    # result:: [String] Binary in Base64
    def self.encode64(data)
      [data].pack('m')
    end

    ##
    # Decode a Base64-encoded String
    # data64:: [String] Binary in Base64
    # result:: [String] Binary
    def self.decode64(data64)
      data64.unpack('m').first
    end
  end
end