Re: Efficient file downloading
- From: James Tucker <jftucker@xxxxxxxxx>
- Date: Thu, 21 Feb 2008 21:24:59 -0500
On 22 Feb 2008, at 01:54, Kyle Hunter wrote:
Hello,
I'm using open-uri to download files using a buffer. It seems very
inefficient in terms of resource usage (CPU is ~10-20% in usage).
If possible, I'd like some suggestions for downloading a file which
names the outputted file the same as the URL, and does not actually
write if the file comes out to a 404 (or some other exception hits).
Current code:
BUFFER_SIZE=4096
Try making that a lot lot bigger.
def download(url)
from = open(url)
if (buffer = from.read(BUFFER_SIZE))
puts "Downloading #{url}"
File.open(url.split('/').last, 'wb') do |file|
begin
file.write(buffer)
end while (buffer = from.read(BUFFER_SIZE))
end
end
end
--
Posted via http://www.ruby-forum.com/.
.
- Follow-Ups:
- Re: Efficient file downloading
- From: Kyle Hunter
- Re: Efficient file downloading
- References:
- Efficient file downloading
- From: Kyle Hunter
- Efficient file downloading
- Prev by Date: Re: Ruby type-safe? Ruby strongly/weakly typed? Ruby pitfalls?
- Next by Date: Re: Efficient file downloading
- Previous by thread: Re: Efficient file downloading
- Next by thread: Re: Efficient file downloading
- Index(es):
Relevant Pages
|
Loading