Created
July 22, 2013 08:29
-
-
Save anildigital/6052241 to your computer and use it in GitHub Desktop.
Rackup script for streaming image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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