app/controllers/random_numbers_controller.rb
# Curl requires the --compressed flag for this response to load correctly.
Curl requires the --compressed flag for this response to load correctly.
Curl requires the -- compressed flag for this response to load correctly .
def stream_json_array(enum)
    headers["Content-Disposition"] = "attachment" 
    headers["Content-Type"]        = "application/json"
    headers["Content-Encoding"]    = "deflate"
    deflate = Zlib::Deflate.new
    buffer = "[\n  "
    enum.each_with_index do |object, i|
      buffer << ",\n  " unless i == 0
      buffer << JSON.pretty_generate(object, depth: 1)
      if i % FLUSH_EVERY == 0
        write(deflate, buffer)
        buffer = ""
      end
    end
    buffer << "\n]\n"
    write(deflate, buffer)
    write(deflate, nil) 
    response.stream.close
  end
def stream_json_array ( enum ) headers [ "Content-Disposition" ] = "attachment" headers [ "Content-Type" ] = "application/json" headers [ "Content-Encoding" ] = "deflate" deflate = Zlib :: Deflate . new buffer = "[\n  " enum . each_with_index do | object , i | buffer << ",\n  " unless i == 0 buffer << JSON . pretty_generate ( object , depth : 1 ) if i % FLUSH_EVERY == 0 write ( deflate , buffer ) buffer = "" end end buffer << "\n]\n" write ( deflate , buffer ) write ( deflate , nil ) response . stream . close end
Curl requires the --compressed flag for this response to load correctly.
Curl requires the -- compressed flag for this response to load correctly .
# Download response to file. It's big. # Flush deflate.
enum