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
3
votes
2 answers

Opening a multipart/form-data ZIP file with rubyzip

I want to extract the files within a ZIP file I uploaded to my Rails app. The files within the ZIP file are going to be stored in the database. I want to open the ZIP file in my action, without first having to save the file to a folder - I want to…
Joerg
  • 3,553
  • 4
  • 32
  • 41
3
votes
5 answers

How to unzip password protected file via Ruby

I'd like to unzip an encrypted/password protected file via a Ruby script without dropping down to a system call. I currently use the rubyzip library to unzip files but don't see an option for working with encrypted files. Anyone know of some code or…
digitalsanctum
  • 3,261
  • 4
  • 29
  • 43
3
votes
3 answers

Generate files and download as zip using RubyZip

For my Ruby on Rails project (Rails version 5.1.2), I'm generating image files (png) and downloading them as a zipfile using RubyZip gem. The image files are not stored in any directory. I have a model called Attachment. Each attachment has an…
jl118
  • 307
  • 2
  • 16
3
votes
1 answer

Rubyzip fail to add a file with a same name from another folder [Zip::EntryExistsError]

Using the following test tree folder for example: - test1 - folder2 - test1 # This is the file rubyzip will break on. - test2 And copied this code from here: path = File.expand_path path archive = File.join(__dir__, File.basename(path)) +…
Hellfar
  • 393
  • 2
  • 17
3
votes
3 answers

NameError - uninitialized constant Zip

I am trying to unzip a file in my Spree plugin. Defined the unzipping method in a module which looks like this. module ImportImages class Zipper def self.unzip(zip, unzip_dir, remove_after = false) Zip::File.open(zip) do |zip_file| …
Aswathy
  • 654
  • 1
  • 12
  • 26
3
votes
2 answers

download and extract remote zip file using rubyzip

I am trying to download a zip file, extract the zip and read the files. Below is my code snippet: url = "http://localhost/my.zip" response = RestClient::Request.execute({:url => url, :method => :get, :content_type => 'application/zip'}) zipfile =…
SOF User
  • 51
  • 3
3
votes
1 answer

Create zip archive without save archiving file to disk in Ruby

I tried to create zip archive without save archiving file to disk. So First I write method with save to disk: begin file = Zip::File.open("#{file_name}.zip", Zip::File::CREATE) save_file file_name file.add(file_name, file_name) rescue IOError…
khusnetdinov
  • 421
  • 5
  • 16
3
votes
2 answers

How to unzip a file with ruby

Okay I've found the following code for unzippping a file with Ruby. def unzip_file (file, destination) Zip::ZipFile.open(file_path) { |zip_file| zip_file.each { |f| f_path=File.join("destination_path", f.name) …
Darkmatter5
  • 1,189
  • 3
  • 12
  • 19
3
votes
1 answer

How to create zip file only in memory in ruby?

I want to create a zip file of all HTML files in a given directory. The zip will be sent as an attachment via email along with the rest of the files from the directory. All email clients I tried so far have trouble reading an email if any attachment…
Radek
  • 13,813
  • 52
  • 161
  • 255
2
votes
2 answers

Ruby storing remote files in Zip using RubyZip

I have a model called Image. Images have files attached using Dragonfly that are stored in S3. I have a requirement that I need to zip up all images. I'm using: Zip::ZipFile.open(tmp_zip, Zip::ZipFile::CREATE) do |zipfile| …
Corey
  • 2,453
  • 4
  • 35
  • 63
2
votes
3 answers

What zip library works well with Ruby 1.9.2?

I used the rubyzip gem in Ruby 1.8.7 before, but I heard rubyzip doesn't work well with ruby 1.9.2. What zip libraries work well with Ruby 1.9.2?
aagustyana
  • 21
  • 3
2
votes
1 answer

RubyZip : Unable to find path of file stored in Active Storage

I am using Rails 5.2 and ActiveStorage to let my users upload files in my app. I have all the uploaded files displayed in a table and I can choose to select which ones I want to download. After selecting, I will be able to download all of them in a…
2
votes
1 answer

rubyzip error when generating zips of images on the fly : End-of-central-directory signature not found

I'm generating a zip file from a collection of images which is then sent to the user. I'm using code which is almost exactly the same as the example given on this…
Simmo
  • 1,717
  • 19
  • 37
2
votes
1 answer

AWS s3 access PRIVATE bucket url from rails app

I'm new to RoR. I'm creating a small app that uploads images and saves them in S3, the user cant attach all the images in a zip file and send it via email,to accomplish that im using rubyzip gem. Locally it works fine (Im following the gem…
2
votes
1 answer

losing data when zipping files

I am using rubyzip on windows to zip up a directory. When I unzip the archive some of the files are smaller than they were. Zipping should be a lossless operation so I am wondering why this is happening. Here is the code I am using: require…
Derek Ekins
  • 11,215
  • 6
  • 61
  • 71
1 2
3
9 10