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
1
vote
1 answer

How to close a ZipFile

I'm passing a dynamic zip file location to a def from a database. I want to unzip the file to a temp location, extract the xml report file inside, apply an xslt stylesheet, copy it as an rhtml to a view directory for rendering, and delete the temp…
Alan Scott
  • 11
  • 2
1
vote
1 answer

How do you upload a zip file and unzip to s3?

I am working on an application where I have to upload a zip file. The zip file is basically a static website so it has many files and a couple subdirectories. I have been playing with the rubyzip gem for a while now and can not figure out how to…
Spencer Cooley
  • 8,471
  • 16
  • 48
  • 63
1
vote
3 answers

unzipping a zip archive from a string

I have a zip archive in a string, but the rubyzip gem appears to want input from a file. The best I've come up with is to write the zip archive to a tempfile for the sole purpose of passing the filename to Zip::ZipFile.foreach(), but this seems…
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
1
vote
1 answer

Rails Zipfile Corrupt when zipping group of mp3 files in tmp on Heroku (Cedar) with rubyzip

I have been working on this for a while. Tried many many different things, I'm totally stumped. I'm trying to download a series of mp3 files from Amazon s3, then store them in Heroku's tmp dir, zip them, then download the file. It works locally,…
1
vote
1 answer

rubyzip/zippy - extract in place

Simple I think but can't seem to find something that works. Using either rubyzip or zippy. I need to extract "path/to/my/file.zip to "path/to/my/file" Documentation is quite slim for either gems.
whyvez
  • 303
  • 3
  • 12
0
votes
1 answer

How to generate password protected (as optional) zip file in Ruby?

Basic archive creation works like this (using rubyzip) Zip::File.open(zipfile_name, create: true) do |zipfile| input_filenames.each do |filename| zipfile.add(filename, File.join(folder, filename)) end end Okay I got that to work a while…
enumag
  • 830
  • 11
  • 21
0
votes
1 answer

IOError: not opened for writing | rubyzip 2.3.2

My project was using zipruby but I need to include a gem which is dependent on rubyzip. Since these two gems gives conflict errors, I decided to switch to rubyzip and in the process for migrating. I was able to handle every other case except the one…
0
votes
1 answer

Extracting excel data after unzipping using rubyzip

I'm trying to get spreadsheet data from zipped .xlsx files. I'm using rubyzip to access the contents of the zipfile Zip::File.open(file_path) do |zip_file| zip_file.each do |entry| *process entry* end end My problem is that rubyzip gives…
0
votes
0 answers

Ruby zipfile delete file causing Errno::ENOENT

I'm trying to work with zip file. I have a document I want to extract, add content to it, replace it and remove the one I extracted. Whenever I just extract the file, add content, and then delete it - every thing works. But when I try to use replace…
Shiranox
  • 101
  • 1
  • 9
0
votes
0 answers

Need help creating zip file archive with rubyzip and rails

New programmer here. I need to create a 'Download Zip' feature on a rails 6 app that generates zipfile containing a directory of subfolders each containing ActiveStorage files. I've read the rubyzip documentation, but I'm just not advanced enough to…
Seth
  • 1
  • 1
0
votes
1 answer

rubyzip file order

I am making an archive for a directory, where each file has a name with 3 digits starting from 001 to 049. My code is the following: Zip::ZipFile.open(File.join(out, dir+".cbz"), Zip::ZipFile::CREATE) { |zipfile| Dir.glob(File.join(dir,…
Ali Lown
  • 2,323
  • 1
  • 18
  • 22
0
votes
1 answer

RubyZip docx issues with write_buffer instead of open

I'm adapting the RubyZip recursive zipping example (found here) to work with write_buffer instead of open and am coming across a host of issues. I'm doing this because the zip archive I'm producing has word documents in it and I'm getting errors on…
0
votes
2 answers

rubyzip: open zip, modify it temporary, send to client

i want to temporary modify a zip file and send the changed file to the client. right now i create a file stream and send it: require 'zip' zip_stream = Zip::OutputStream.write_buffer do |zip| zip.put_next_entry 'new_folder/file' …
mace
  • 11
  • 4
0
votes
1 answer

Is it possible to read pdf file inside rubyzip by pdf-reader?

Is it possible to read a PDF file inside a zip file by pdf-reader? I tried this code but it does not work. require 'zip' Zip::File.open('/path/to/zipfile') do |zip_file| zip_file.each do |entry| if entry.directory? puts "#{entry.name} is a…
Tjax
  • 323
  • 1
  • 5
  • 12
0
votes
0 answers

Ruby on rails : uninitialized constant Zip::File::Create

I'm trying to zip folder with rubyzip gem, I got this error : uninitialized constant Zip::File::Create this the method that create the zip : def self.zip_pdf( report, paths ) if…
user9569059