E
Elliot Temple
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
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