[#1058] ruby 0.99.3-961119 available — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです.

19 messages 1996/11/19
[#1059] segm fault (Re ruby 0.99.3-961119 available) — sinara@... 1996/11/19

原です。

[ruby-list:1015] decode64

From: WATANABE Hirofumi <watanabe@...>
Date: 1996-11-13 01:22:45 UTC
List: ruby-list #1015
渡辺@ソニーです.

yet another な decode64 です. perl からの移植. uuencoded
format に変換しちゃうってのがなかなかのアイディアですね.

def decode64(str)
  string = ''
  for line in str.split("\n")
    line.delete!('^A-Za-z0-9+')		# remove non-base64 chars
    line.tr!('A-Za-z0-9+', ' -_')	# convert to uuencoded format
    len = ["#{32 + line.length * 3 / 4}"].pack("c")
					# compute length byte
    string += "#{len}#{line}".unpack("u") # uudecode and concatenate
  end
  return string
end

オリジナルは Tom Christiansen の

#!/usr/bin/perl
while (<>) {
  tr#A-Za-z0-9+/##cd;                   # remove non-base64 chars
  tr#A-Za-z0-9+/# -_#;                  # convert to uuencoded format
  $len = pack("c", 32 + 0.75*length);   # compute length byte
  print unpack("u", $len . $_);         # uudecode and print
}

です.

-- 
わたなべひろふみ

In This Thread

Prev Next