Module: ZipTricks::RailsStreaming
- Defined in:
- lib/zip_tricks/rails_streaming.rb
Overview
Should be included into a Rails controller for easy ZIP output from any action.
Instance Method Summary collapse
-
#zip_tricks_stream(**zip_streamer_options) {|Streamer| ... } ⇒ ZipTricks::OutputEnumerator
Opens a Streamer and yields it to the caller.
Instance Method Details
#zip_tricks_stream(**zip_streamer_options) {|Streamer| ... } ⇒ ZipTricks::OutputEnumerator
Opens a Streamer and yields it to the caller. The output of the streamer gets automatically forwarded to the Rails response stream. When the output completes, the Rails response stream is going to be closed automatically.
12 13 14 15 16 17 18 19 |
# File 'lib/zip_tricks/rails_streaming.rb', line 12 def zip_tricks_stream(**, &zip_streaming_blk) # Set a reasonable content type response.headers['Content-Type'] = 'application/zip' # Make sure nginx buffering is suppressed - see https://github.com/WeTransfer/zip_tricks/issues/48 response.headers['X-Accel-Buffering'] = 'no' response.sending_file = true self.response_body = ZipTricks::OutputEnumerator.new(**, &zip_streaming_blk) end |