rtomayko (owner)

Forks

Revisions

gist: 70323 Download_button fork
public
Description:
Sinatra: Iterative/streamed response generation
Public Clone URL: git://gist.github.com/70323.git
Embed All Files: show embed
iterativeapp.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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