Skip to content

Instantly share code, notes, and snippets.

@joaodrp
Created January 25, 2012 12:04
Show Gist options
  • Save joaodrp/1675971 to your computer and use it in GitHub Desktop.
Save joaodrp/1675971 to your computer and use it in GitHub Desktop.
#
# s3_store.rb
#
require "em-synchrony"
require "em-synchrony/em-http"
class S3Store
def initialize(uri)
@uri = uri
end
def get
http = EventMachine::HttpRequest.new(@uri).aget
finish = proc { env.chunked_stream_close } # undefined local variable or method `env'
http.stream { |chunk| yield chunk }
http.callback &finish
http.errback &finish
end
end
#
# server.rb
#
require 'goliath'
require 'json'
class GetImage < Goliath::API
def response(env)
store = S3Store.new('http://dl.dropbox.com/u/3528102/10.iso') #10mb file
EM.next_tick do
store.get { |chunk| env.chunked_stream_send chunk }
end
headers = {'Content-Type' => 'application/octet-stream', 'X-Stream' => 'Goliath'}
chunked_streaming_response(200, headers)
end
end
class Server < Goliath::API
get '/image', GetImage
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment