Skip to content

Instantly share code, notes, and snippets.

@ismasan
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismasan/47e1544373dd4c062b20 to your computer and use it in GitHub Desktop.
Save ismasan/47e1544373dd4c062b20 to your computer and use it in GitHub Desktop.
Spiking streaming HTTP downloads in Ruby
# Here we can't really make sure that each chunk is a line.
Net::HTTP.start(uri.host, uri.port, use_ssl:true) do |http|
request = Net::HTTP::Get.new uri
# request.basic_auth 'user', 'pwd'
http.request request do |response|
response.read_body do |chunk|
CSV.parse(chunk).each do |line|
puts line
puts 'END'
end
end
end
end
s = TCPSocket.new uri.host, uri.port
s.write "GET #{uri.path}\r\n"
s.write "\r\n"
while line = s.gets
puts line
end
s.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment