Skip to content

Instantly share code, notes, and snippets.

@adam12
Created March 29, 2019 14:49
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 adam12/339f18b304374cbe6b734bfb0522ba35 to your computer and use it in GitHub Desktop.
Save adam12/339f18b304374cbe6b734bfb0522ba35 to your computer and use it in GitHub Desktop.
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "iodine", "0.7.27"
gem "puma", "3.12.1"
gem "down", "4.6.1"
gem "roda"
end
module EachChunk
def each_chunk(chunk_size = 1024)
yield read(chunk_size) until eof?
end
end
app = Class.new(Roda) do
plugin :streaming
route do |r|
data = StringIO.new("This is the data")
input = Down::ChunkedIO.new(
size: data.size,
chunks: data.extend(EachChunk).enum_for(:each_chunk),
data: {
content_type: "text/plain"
}
)
stream do |output|
IO.copy_stream(input, output)
end
end
end
server = ARGV[0] or abort "Usage: #{$0} iodine|puma"
Rack::Server.start(app: app, server: server.to_sym, :Port => 9292)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment