Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: base64.rb
#
[0] Fix | Delete
# = base64.rb: methods for base64-encoding and -decoding stings
[1] Fix | Delete
#
[2] Fix | Delete
# Author:: Yukihiro Matsumoto
[3] Fix | Delete
# Documentation:: Dave Thomas and Gavin Sinclair
[4] Fix | Delete
#
[5] Fix | Delete
# Until Ruby 1.8.1, these methods were defined at the top-level. Now
[6] Fix | Delete
# they are in the Base64 module but included in the top-level, where
[7] Fix | Delete
# their usage is deprecated.
[8] Fix | Delete
#
[9] Fix | Delete
# See Base64 for documentation.
[10] Fix | Delete
#
[11] Fix | Delete
[12] Fix | Delete
require "kconv"
[13] Fix | Delete
[14] Fix | Delete
[15] Fix | Delete
# The Base64 module provides for the encoding (#encode64) and decoding
[16] Fix | Delete
# (#decode64) of binary data using a Base64 representation.
[17] Fix | Delete
#
[18] Fix | Delete
# The following particular features are also provided:
[19] Fix | Delete
# - encode into lines of a given length (#b64encode)
[20] Fix | Delete
# - decode the special format specified in RFC2047 for the
[21] Fix | Delete
# representation of email headers (decode_b)
[22] Fix | Delete
#
[23] Fix | Delete
# == Example
[24] Fix | Delete
#
[25] Fix | Delete
# A simple encoding and decoding.
[26] Fix | Delete
#
[27] Fix | Delete
# require "base64"
[28] Fix | Delete
#
[29] Fix | Delete
# enc = Base64.encode64('Send reinforcements')
[30] Fix | Delete
# # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
[31] Fix | Delete
# plain = Base64.decode64(enc)
[32] Fix | Delete
# # -> "Send reinforcements"
[33] Fix | Delete
#
[34] Fix | Delete
# The purpose of using base64 to encode data is that it translates any
[35] Fix | Delete
# binary data into purely printable characters. It is specified in
[36] Fix | Delete
# RFC 2045 (http://www.faqs.org/rfcs/rfc2045.html).
[37] Fix | Delete
[38] Fix | Delete
module Base64
[39] Fix | Delete
module_function
[40] Fix | Delete
[41] Fix | Delete
# Returns the Base64-decoded version of +str+.
[42] Fix | Delete
#
[43] Fix | Delete
# require 'base64'
[44] Fix | Delete
# str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
[45] Fix | Delete
# 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
[46] Fix | Delete
# 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
[47] Fix | Delete
# puts Base64.decode64(str)
[48] Fix | Delete
#
[49] Fix | Delete
# <i>Generates:</i>
[50] Fix | Delete
#
[51] Fix | Delete
# This is line one
[52] Fix | Delete
# This is line two
[53] Fix | Delete
# This is line three
[54] Fix | Delete
# And so on...
[55] Fix | Delete
[56] Fix | Delete
def decode64(str)
[57] Fix | Delete
str.unpack("m")[0]
[58] Fix | Delete
end
[59] Fix | Delete
[60] Fix | Delete
[61] Fix | Delete
# Decodes text formatted using a subset of RFC2047 (the one used for
[62] Fix | Delete
# mime-encoding mail headers).
[63] Fix | Delete
#
[64] Fix | Delete
# Only supports an encoding type of 'b' (base 64), and only supports
[65] Fix | Delete
# the character sets ISO-2022-JP and SHIFT_JIS (so the only two
[66] Fix | Delete
# encoded word sequences recognized are <tt>=?ISO-2022-JP?B?...=</tt> and
[67] Fix | Delete
# <tt>=?SHIFT_JIS?B?...=</tt>). Recognition of these sequences is case
[68] Fix | Delete
# insensitive.
[69] Fix | Delete
[70] Fix | Delete
def decode_b(str)
[71] Fix | Delete
str.gsub!(/=\?ISO-2022-JP\?B\?([!->@-~]+)\?=/i) {
[72] Fix | Delete
decode64($1)
[73] Fix | Delete
}
[74] Fix | Delete
str = Kconv::toeuc(str)
[75] Fix | Delete
str.gsub!(/=\?SHIFT_JIS\?B\?([!->@-~]+)\?=/i) {
[76] Fix | Delete
decode64($1)
[77] Fix | Delete
}
[78] Fix | Delete
str = Kconv::toeuc(str)
[79] Fix | Delete
str.gsub!(/\n/, ' ')
[80] Fix | Delete
str.gsub!(/\0/, '')
[81] Fix | Delete
str
[82] Fix | Delete
end
[83] Fix | Delete
[84] Fix | Delete
# Returns the Base64-encoded version of +str+.
[85] Fix | Delete
#
[86] Fix | Delete
# require 'base64'
[87] Fix | Delete
# Base64.b64encode("Now is the time for all good coders\nto learn Ruby")
[88] Fix | Delete
#
[89] Fix | Delete
# <i>Generates:</i>
[90] Fix | Delete
#
[91] Fix | Delete
# Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
[92] Fix | Delete
# UnVieQ==
[93] Fix | Delete
[94] Fix | Delete
def encode64(bin)
[95] Fix | Delete
[bin].pack("m")
[96] Fix | Delete
end
[97] Fix | Delete
[98] Fix | Delete
# _Prints_ the Base64 encoded version of +bin+ (a +String+) in lines of
[99] Fix | Delete
# +len+ (default 60) characters.
[100] Fix | Delete
#
[101] Fix | Delete
# require 'base64'
[102] Fix | Delete
# data = "Now is the time for all good coders\nto learn Ruby"
[103] Fix | Delete
# Base64.b64encode(data)
[104] Fix | Delete
#
[105] Fix | Delete
# <i>Generates:</i>
[106] Fix | Delete
#
[107] Fix | Delete
# Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
[108] Fix | Delete
# UnVieQ==
[109] Fix | Delete
[110] Fix | Delete
def b64encode(bin, len = 60)
[111] Fix | Delete
encode64(bin).scan(/.{1,#{len}}/) do
[112] Fix | Delete
print $&, "\n"
[113] Fix | Delete
end
[114] Fix | Delete
end
[115] Fix | Delete
[116] Fix | Delete
[117] Fix | Delete
module Deprecated # :nodoc:
[118] Fix | Delete
include Base64
[119] Fix | Delete
[120] Fix | Delete
for m in Base64.private_instance_methods(false)
[121] Fix | Delete
module_eval %{
[122] Fix | Delete
def #{m}(*args)
[123] Fix | Delete
warn("\#{caller(1)[0]}: #{m} is deprecated; use Base64.#{m} instead")
[124] Fix | Delete
super
[125] Fix | Delete
end
[126] Fix | Delete
}
[127] Fix | Delete
end
[128] Fix | Delete
end
[129] Fix | Delete
end
[130] Fix | Delete
[131] Fix | Delete
include Base64::Deprecated
[132] Fix | Delete
[133] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function