try to speed up ydecoding

This commit is contained in:
Ward Wouts 2002-08-05 21:01:17 +00:00
parent 97cec78a66
commit fdd4a45195

View file

@ -255,6 +255,7 @@ def get_body(server, message)
rescue Net::NNTPReplyError rescue Net::NNTPReplyError
print "Caught Net::NNTPReplyError reading article #{message} from #{server} (get_body)\n" print "Caught Net::NNTPReplyError reading article #{message} from #{server} (get_body)\n"
print "Error: #{$!}\n" print "Error: #{$!}\n"
print "Status: #{$?}\n"
return false return false
rescue EOFError rescue EOFError
print "Caught EOFError reading article #{message} from #{server} (get_body)\n" print "Caught EOFError reading article #{message} from #{server} (get_body)\n"
@ -710,6 +711,11 @@ def _ydecode_file(file, outfile)
total = 0 total = 0
oldpartend = 0 oldpartend = 0
ymap=[]
(0..255).each do |b|
ymap.push((b-42+256)%256)
end
while (! file.eof) while (! file.eof)
line = file.gets line = file.gets
print "line: #{line}" if Debuglevel > 0 print "line: #{line}" if Debuglevel > 0
@ -747,7 +753,7 @@ def _ydecode_file(file, outfile)
while (! file.eof) while (! file.eof)
print "at #{file.pos} need to go to #{lines}\n" if Debuglevel > 1 print "at #{file.pos} need to go to #{lines}\n" if Debuglevel > 1
line = file.gets line = file.gets
line = line[0 ... line.length - 1] line.chomp!
if line =~ /^=yend\s+(.*)\Z/ if line =~ /^=yend\s+(.*)\Z/
m = $1 m = $1
@ -805,20 +811,31 @@ def _ydecode_file(file, outfile)
# if line.length != linesize # if line.length != linesize
# print "linesize mismatch, was #{line.length}, should be #{linesize}...\n" # print "linesize mismatch, was #{line.length}, should be #{linesize}...\n"
# end # end
special = 0
line.each_byte { |b| i = 0
if special == 0 while i < line.length
if b == 0x3d if line[i] == '='
special = 1 i += 1
next line[i] -= 64
end
else
special = 0
b = (b - 64) % 256
end end
outfile.putc((b - 42) % 256) outfile.putc ymap[line[i]]
bytes += 1 bytes += 1
} end
# special = 0
# line.each_byte { |b|
# if special == 0
# if b == 0x3d
# special = 1
# next
# end
# else
# special = 0
# b = (b - 64) % 256
# end
# outfile.putc((b - 42) % 256)
# bytes += 1
# }
end end
print "No \"=yend\" found!!!\n" print "No \"=yend\" found!!!\n"