From: "ara.t.howard" Date: 2008-11-07T08:31:54+09:00 Subject: Re: Partial Read From URL On Nov 6, 2008, at 4:24 PM, Elliot Temple wrote: > Can anyone see a problem with this code to read only 20k from a URL? > The > http connection will get closed, right? > > Is there a better way to do this? My goal is to download the start of > mp3 files and then estimate their duration without downloading the > entire file. > > def partial_uri_read(uri) > u = URI.parse(uri) > s = "" > Net::HTTP.start(u.host, u.port) do |http| > http.request_get(u.path) do |response| > response.read_body do |chunk| > s << chunk > return s if s.size > 20000 > end > end > end > s > end > > Thanks > Elliot Temple > -- > Posted via http://www.ruby-forum. maybe try require 'open-uri' uri = ...... open(uri){|fd| fd.read 20000} a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama