1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/base64.rb
matz 210367ec88 This commit was generated by cvs2svn to compensate for changes in r372,
which included commits to RCS files with non-trunk default branches.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1999-01-20 04:59:39 +00:00

29 lines
472 B
Ruby

require "kconv"
def decode64(str)
str.unpack("m")[0]
end
def decode_b(str)
str.gsub!(/=\?ISO-2022-JP\?B\?([!->@-~]+)\?=/i) {
decode64($1)
}
str = Kconv::toeuc(str)
str.gsub!(/=\?SHIFT_JIS\?B\?([!->@-~]+)\?=/i) {
decode64($1)
}
str = Kconv::toeuc(str)
str.gsub!(/\n/, ' ')
str.gsub!(/\0/, '')
str
end
def encode64(bin)
[bin].pack("m")
end
def b64encode(bin, len = 60)
encode64(bin).scan(/.{1,#{len}}/o) do
print $&, "\n"
end
end