Questions tagged [rubyzip]

a ruby library for reading and writing zip files

rubyzip is a ruby library for reading and writing zip files.

Requirements - Ruby 1.9.2 or greater

There is more than one way to access or create a zip archive with rubyzip. The basic is modeled after the classes in java.util.zip from the Java SDK. This means there are classes such as Zip::ZipInputStream, Zip::ZipOutputStream and Zip::ZipFile. Zip::ZipInputStream provides a basic interface for iterating through the entries in a zip archive and reading from the entries in the same way as from a regular File or IO object. ZipOutputStream is the corresponding basic output facility. Zip::ZipFile provides a mean for accessing the archives central directory and provides means for accessing any entry without having to iterate through the archive. Unlike Java‘s java.util.zip.ZipFile rubyzip‘s Zip::ZipFile is mutable, which means it can be used to change zip files as well.

Another way to access a zip archive with rubyzip is to use rubyzip‘s Zip::ZipFileSystem API. Using this API files can be read from and written to the archive in much the same manner as ruby‘s built-in classes allows files to be read from and written to the file system.

rubyzip also features the zip/ziprequire.rb module which allows ruby to load ruby modules from zip archives.

Links

Related tag

136 questions
0
votes
1 answer

Send zip binary data over ActionCable

An ActiveJob generates a zip in a Tempfile, reads its data to a variable, upon completion of the job, broadcasts the data, Base64 encoded, to the client, client downloads data via saveAs The end result can't be decompressed/is corrupted. I suspect…
0
votes
1 answer

rubyzip coaching

Zip::ZipOutputStream.open(folderpath) do |z| z.print IO.read(folderpath) In the code above, I have Zip::ZipOutputStream.open(file_path) do |z|. I do not understand, what the do |z| mean? What does |z| refer to? Can I for example change…
rahardi
  • 213
  • 1
  • 5
  • 12
0
votes
0 answers

How do I adapt the RubyZip sample to utilize File.write_buffer instead of File.open when constructing a zip file?

How do I adapt the following sample that utilizes File.open when constructing a zip file to utilizing write_buffer instead of File.open as given in the next code sample? Here is the File.open sample: require 'zip' # This is a simple example which…
Davie Overman
  • 114
  • 1
  • 13
0
votes
1 answer

Ruby: 'Zip is not installed' error message when running on Win CMD this: buildpack-packager --uncached

I'm running cmd command buildpack-packer --uncached (or any other option of buildpack-packer). I had many error messages prior that. They were caused by bad content of manifest.yml. I corrected them. So now I receive this error message: Zip is not…
Andr
  • 88
  • 1
  • 10
0
votes
1 answer

RubyZip set file timestamps

I have been banging my head the whole day on this, maybe you can help? I am zipping the file with RubyZip and I need to set the time of that file creation/update/modification to the certain time in time zone (which depends on the client time zone I…
Maris
  • 664
  • 1
  • 5
  • 15
0
votes
1 answer

Paperclip processor can't find it's file

Formerly: Running a model method on a paperclip attachment after create or update (paperclip callbacks don't seem to work) Edit (later that day) I figured out my problem. The processor apparently works with the file that is updated, but doesn't…
Josh Kovach
  • 7,679
  • 3
  • 45
  • 62
0
votes
0 answers

open zip file using rubyzip

def extract_zip(file, destination) FileUtils.mkdir_p(destination) Zip::ZipFile.open(file) do |zip_file| zip_file.each do |f| file_path = File.join(destination, f.name) zip_file.extract(entry, file_path) unless File.exist?(file_path) …
msc
  • 67
  • 8
0
votes
1 answer

rubyzip extracts empty file in activejob

I have a function in my activejob that extracts a specific file from a zip file. Following code extracted empty file. def extract_file(from, name) to = get_local_dest(name) Zip::File.open(from) do |zip_file| entry =…
0
votes
1 answer

Could not find 'rubyzip' (~> 1.0)

When trying to execute my ruby script I receive the following error message C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/dependency.rb:308:in `to_specs': Could not find 'rubyzip' (~> 1.0) among 14 total gem(s) (Gem::MissingSpecError) Checked in…
user3531858
  • 155
  • 5
  • 17
0
votes
0 answers

Roo Gem and RubyZip Working together

We use Roo to handle the spreadsheets that are upload. Everything works fine. A request was put in to allow for a zip file with multiple excel docs in it. I went out and added gem 'rubyzip', '>= 1.0.0' and ran bundle install. Following the…
cal1801
  • 135
  • 1
  • 11
0
votes
1 answer

rubyzip Zip::FileSystem::ZipFsDir glob method broken?

Using version 1.2.0, I am getting strange results when I try to call glob on a ZipFsDir object. In a rails console: > require 'zip/filesystem' => true > file = '/home/me/test.zip' => "/home/me/test.zip" > zf = Zip::File.open file =>…
KenB
  • 6,587
  • 2
  • 35
  • 31
0
votes
1 answer

uninitialized constant Zip::Archive

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…
0
votes
1 answer

Read zip example in readme.md - undefined local variable or method `dest_file' for main:Object (NameError)

Implementing the example code in ready.md, I get the error above. Searching through the source I can't find a method dest_file. The code I've implemented - require 'rubygems' require 'zip' Zip::File.open('test.zip') do |zip_file| # Handle entries…
dan
  • 1,030
  • 1
  • 9
  • 24
0
votes
1 answer

Ruby zip cannot open docx file

What I'm doing is trying to open a blank docx with rubyzip and i keep getting the error: Zip::Error: File /b;a/bla/bla/existing_file.docx not found Is there a rule in rubyzip that prevents opening empty zipfiles?
Robin Winton
  • 591
  • 10
  • 23
0
votes
1 answer

RubyZip turning JPGs into "not JPGs, starts with 0x89"

I'm using RubyZip to compress a set of images (uploaded using Paperclip) and allow the user to download them in one file, and all works fine until I come to open an image. It wont display, and trying on Ubuntu I get the error message: "Error…
wastedhours
  • 257
  • 5
  • 14