Creating a zip file in memory not on disc

hi how i can create zip file in memory?
below is my code.
require ‘csv’
require ‘pry’
require ‘stringio’
require ‘tempfile’
require ‘rubygems’
require ‘zip’
#reading local csv file
table = CSV.parse(File.read(“sunil_test.csv”), headers: true)

#creating csv file in memory
temp_file = CSV.generate do |csv|
csv << table
end
stringio = Zip::OutputStream.write_buffer do |zio|
zio.put_next_entry(“my_data.csv”)
zio.write temp_file
end
stringio.rewind #reposition buffer pointer to the beginning
binding.pry
#below line is creating zip file on disc
File.new(“test.zip”,“wb”).write(stringio.sysread) #write buffer to zipfile

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs