-
-
Save adam12/339f18b304374cbe6b734bfb0522ba35 to your computer and use it in GitHub Desktop.
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 "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