Created
February 25, 2009 18:11
-
-
Save rtomayko/70323 to your computer and use it in GitHub Desktop.
Sinatra: Iterative/streamed response generation
This file contains hidden or 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 'sinatra' | |
class DatabaseStreamer | |
def initialize(blob) | |
@blob = blob | |
end | |
def each | |
while chunk = @blob.read(4096) | |
yield chunk | |
end | |
end | |
end | |
get '/iterative' do | |
blob = db.go_get_me_some_blob(...) | |
DatabaseStreamer.new(blob) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment