Created
August 28, 2013 12:09
-
-
Save jamiehodge/6365307 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
def download | |
content = Zoid::Content.new | |
content.write(resource.file.read) | |
res.body = content | |
res.body.close | |
serve | |
throw :halt | |
end |
judofyr
commented
Aug 28, 2013
def download
res.headers.content_type = resource.type
res.body.total_size = resource.file.size
serve
io = resource.file
until io.eof? do
begin
Fiber.yield (res.body << io.read_nonblock(4096))
rescue IO::WaitReadable
IO.select([io])
retry
end
end
res.body.close
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment