From: "toulax@..." Date: 2007-03-26T06:00:06+09:00 Subject: Re: Read only a few bytes from file On Mar 25, 9:59 am, Rob Biedenharn wrote: > On Mar 25, 2007, at 7:10 AM, tou...@gmail.com wrote: > > > Is there any way to read only a determined amount of bytes from a > > specific file? I actually want to do that to a URL, but I assume the > > procedure would be the same. > > > If someone could at least point me to the right direction that would > > be great! > > > Thanks > > Initial contents ofhttp://conferences.oreillynet.com/rails/ > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > > > RailsConf 2007 • May 17, 2007 - May 20, 2007 • > Portland, Oregon > > > > > > > > > $ irb > >> require 'open-uri' > => true > >> open('http://conferences.oreillynet.com/rails/') { |f| > ?> f.pos = 182 > >> puts f.read(14) > >> } > RailsConf 2007 > => nil > > open-uri extends Kernel#open to understand how to read from HTTP and > FTP sources > IO#pos= sets the offset > IO#read returns up to the number of bytes requested > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...@AgileConsultingLLC.com This works, however it still reads the entire page but only displays the certain amount of bytes. Is it possible to only load the amount of bytes that I specify? Say for instance that I have a 10mb file, how do I get the first few bytes of this file without having to read it entirely first? Thanks