Sha256: ea4990f6db860bb701dbd9e69dc51478908dc3455b937ac71463b92dbe2ed155

Contents?: true

Size: 819 Bytes

Versions: 2

Compression:

Stored size: 819 Bytes

Contents

# 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
    response.headers['Content-Type'] = 'application/zip'
    # 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

2 entries across 2 versions & 1 rubygems

Version Path
zip_tricks-4.4.2 lib/zip_tricks/rails_streaming.rb
zip_tricks-4.4.1 lib/zip_tricks/rails_streaming.rb