Skip to content

Instantly share code, notes, and snippets.

@anildigital
Created July 22, 2013 08:29
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 anildigital/6052241 to your computer and use it in GitHub Desktop.
Save anildigital/6052241 to your computer and use it in GitHub Desktop.
Rackup script for streaming image
require 'rack/stream'
use Rack::Stream
run lambda {|env|
stream = env['rack.stream']
stream.after_open do
times = 0
open("./moi_munnar_up.jpg", "rb") {|f|
while (line = f.gets)
stream.chunk line
sleep 0.01
times += 1
end
}
puts "Times is #{times}"
stream.close # <-- It's your responsibility to close the connection
end
[200, {'Content-Type' => 'image/jpeg'}, []] # <-- downstream response bodies are also streamed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment