E
Eivind
Hi,
I'm a Ruby newbie fra Norway (say that many times fast
Currently i'm trying to send files from one application to another
using distributed ruby (dRuby).
The files are sent, but it takes "forever".
I tried to send a Word-document (about 600 kB), and it took more than
two minutes when both applications ran locally on the same machine.
Do I have to do something special if I'm working with files other than
ordinary text?
This is the code I'm using:
###
def fetch(fname)
File.open(fname, 'r') do |fp|
while buf = fp.read(4096)
yield(buf)
end
end
return nil
end
def store_from(fname, there)
puts
size = there.size(fname)
wrote = 0
File.rename(fname, fname + '.bak') if File.exists? fname
File.open(fname, 'w') do |fp|
yield([wrote, size]) if block_given?
there.fetch(fname) do |buf|
wrote += fp.write(buf)
yield([wrote, size]) if block_given?
nil
end
fp.close
end
return wrote
end
I'm a Ruby newbie fra Norway (say that many times fast
Currently i'm trying to send files from one application to another
using distributed ruby (dRuby).
The files are sent, but it takes "forever".
I tried to send a Word-document (about 600 kB), and it took more than
two minutes when both applications ran locally on the same machine.
Do I have to do something special if I'm working with files other than
ordinary text?
This is the code I'm using:
###
def fetch(fname)
File.open(fname, 'r') do |fp|
while buf = fp.read(4096)
yield(buf)
end
end
return nil
end
def store_from(fname, there)
puts
size = there.size(fname)
wrote = 0
File.rename(fname, fname + '.bak') if File.exists? fname
File.open(fname, 'w') do |fp|
yield([wrote, size]) if block_given?
there.fetch(fname) do |buf|
wrote += fp.write(buf)
yield([wrote, size]) if block_given?
nil
end
fp.close
end
return wrote
end