From: "toulax@..." Date: 2007-03-26T07:15:05+09:00 Subject: Re: Read only a few bytes from file On Mar 25, 6:49 pm, Timothy Hunter wrote: > tou...@gmail.com wrote: > > 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? > > Specify the number of bytes you want to the read method. Because of > buffering read may actually read more bytes than you want, but it won't > be all 10mb. I tested on a URL with around 200kb and it took the exact same time reading it all vs reading only 8 bytes. I believe this is done in PHP via sockets, isn't the same possible with Ruby?