Skip to content

Instantly share code, notes, and snippets.

@jamiehodge
Created August 28, 2013 12:09
Show Gist options
  • Save jamiehodge/6365307 to your computer and use it in GitHub Desktop.
Save jamiehodge/6365307 to your computer and use it in GitHub Desktop.
def download
content = Zoid::Content.new
content.write(resource.file.read)
res.body = content
res.body.close
serve
throw :halt
end
@jamiehodge
Copy link
Author

    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