From: _why Date: 2008-09-23T04:00:50+09:00 Subject: Re: Streaming media with net/http On Tue, Sep 23, 2008 at 03:24:49AM +0900, William Spitzer wrote: > So I was wondering how one would capture a continuous stream of data > (for instance a net radio station or a webcam) with the net/http > library? Here's an example of streaming the Ubuntu ISO with Net::HTTP: require 'net/http' uri = URI("http://mirrors.us.kernel.org/ubuntu-releases/hardy/ubuntu-8.04.1-desktop-i386.iso") Net::HTTP.get_response(uri) do |res| size, total = 0, res.header['Content-Length'].to_i res.read_body do |chunk| size += chunk.size puts "%d%% done (%d of %d)" % [(size * 100) / total, size, total] end end So, before the `read_body` block, you can examine the headers. And inside the `read_body` block, you can handle chunks as they come in. In your case, you'd pass them to file.write. _why