Reputation: 23
Initially i have used zipruby gem and upgrading the rails environment and try to switch rubyzip. then what will be the equivalent of this.
Used gem in gem file - gem 'rubyzip',gem 'nokogiri',rails-4.1.9,ruby -2.2
Zip::Archive.open("#{@docx_file.path}") do |dest|
n = dest.num_files
n.times do |i|
case dest.get_name(i)
when 'word/document.xml'
dest.replace_buffer i, @docx[:template].to_xml
else
#
end
end
end
issue -uninitialized constant Zip::Archive
Upvotes: 0
Views: 834
Reputation: 55718
According to the README file of the rubyzip gem, the correct class to use is Zip::File
. You can read a zip file by using
Zip::File.open('foo.zip') do |zip_file|
# Handle entries one by one
zip_file.each do |entry|
# Extract to file/directory/symlink
puts "Extracting #{entry.name}"
entry.extract(dest_file)
# Read into memory
content = entry.get_input_stream.read
end
# Find specific entry
entry = zip_file.glob('*.csv').first
puts entry.get_input_stream.read
end
Please read the documentation available to you.
Upvotes: 3