Sha256: bd5503622c08271b75e0039cc694a5f978083a8804e60f4ab0e9e7765c0b34cd
Contents?: true
Size: 1.02 KB
Versions: 15
Compression:
Stored size: 1.02 KB
Contents
# frozen_string_literal: true # Should be included into a Rails controller (together with `ActionController::Live`) # for easy ZIP output from any action. module ZipTricks::RailsStreaming # Opens a {ZipTricks::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. # @yield [Streamer] the streamer that can be written to def zip_tricks_stream # 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' # Create a wrapper for the write call that quacks like something you # can << to, used by ZipTricks w = ZipTricks::BlockWrite.new { |chunk| response.stream.write(chunk) } ZipTricks::Streamer.open(w) { |z| yield(z) } ensure response.stream.close end end
Version data entries
15 entries across 15 versions & 1 rubygems