class Net::InternetMessageIO

def buffer_filling(buf, src)

def buffer_filling(buf, src)
  case src
  when String    # for speeding up.
    0.step(src.size - 1, 1024) do |i|
      buf << src[i, 1024]
      yield
    end
  when File    # for speeding up.
    while s = src.read(1024)
      buf << s
      yield
    end
  else    # generic reader
    src.each do |str|
      buf << str
      yield if buf.size > 1024
    end
    yield unless buf.empty?
  end
end