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

rubyzip undefined method `to_binary_dos_time' for

The below message getting logged when I try to open zip file with write mode. Full Error Message : undefined method `to_binary_dos_time' for 2017-05-30 15:07:21 +0530:Time Backtrace : …
Satishakumar Awati
  • 3,604
  • 1
  • 29
  • 50
2
votes
1 answer

find whether a zipped file is text or binary without unzipping it

I'm creating a ruby script which goes through several zip files and validates the content of any xml files within. To optimise my script, I'm using the ruby-zip gem to open the zip files without extracting them. My initial thought was to use…
eiko
  • 5,110
  • 6
  • 17
  • 35
2
votes
0 answers

How to set binary-flag in Zip-file with rubyzip?

I received a complain about a zip file I created with rubyzip 1.2.0: The text flag for text.pdf corrupted the pdf after unpacking. I create the zip under windows, the recipient works with Unix/Linux. You can see the flag with zipinfo (or unzip -Z…
knut
  • 27,320
  • 6
  • 84
  • 112
2
votes
1 answer

How to add existing file to ZIP file using RubyZIP?

In my Rails 4.2 application I am using RubyZIP to create a controller action similar to the following: class SomeController < ApplicationController def some_action file_stream = Zip::ZipOutputStream.write_buffer do |zip| …
Tintin81
  • 9,821
  • 20
  • 85
  • 178
2
votes
0 answers

RubyZip fails - closed stream

I have a chef-cookbook with following ruby code: class Chef::Recipe::Helpers def self.is_config?(filename) ['.lua', '.conf'].include?(File.extname(filename)) end def self.out_filename(filename) File.extname(filename) == '.conf' ?…
Scooby
  • 3,371
  • 8
  • 44
  • 84
2
votes
1 answer

Zipped Tempfile only sending half the time - using Rubyzip

The following code is meant to aggregate a handful of PDF docs and send a zip file with all the PDF's contained. The code works, but only 50% of the time. def donor_reports @starting_date = params['date'].to_date @ending_date =…
EHawk
  • 21
  • 1
2
votes
1 answer

RubyZip Unzipping .docx, modifying, and zipping back up throws Errno::EACCESS error

So, I'm using Nokogiri and Rubyzip to unzip a .docx file, modify the word/docoument.xml file in it (in this case just change every element wrapped in to say "Dreams!"), and then zip it back up. require 'nokogiri' require 'zip' zip =…
Brewster
  • 195
  • 1
  • 1
  • 9
2
votes
1 answer

Rubyzip error causing havoc in my logs

Essentially my log files look something like this right now: Invalid date/time in zip entry Invalid date/time in zip entry Invalid date/time in zip entry Invalid date/time in zip entry Invalid date/time in zip entry Invalid date/time in zip…
Matt Visser
  • 102
  • 8
2
votes
1 answer

Compress JSON response in zip and download it When user hit h URL in Rails

i am new in Rails . i want to compress JSON response in zip format and download it when user hit a specific url. my controller code is below api :GET, '/tv/latest', 'Get latest tvs.' error :code => 401, :desc => "Unauthorized" description "Get…
Faysal
  • 47
  • 1
  • 9
2
votes
2 answers

How to read specific columns of a zipped CSV file

I used the code below to read the contents of a zipped CSV file. Zip::ZipFile.foreach(file) do |entry| istream = entry.get_input_stream data = istream.read #... end It gives me the entire content of the text (CSV) file with headers like…
user28
  • 249
  • 2
  • 7
  • 20
2
votes
1 answer

Play2 Chef cookbook not installing on Vagrant machine

I tried adding this Play2 cookbook to my list of cookbooks to be run with Vagrant, and upon doing vagrant provision I get the error FATAL: Gem::InstallError: chef_gem[rubyzip] (play2::default line 20) had an error: Gem::InstallError: rubyzip…
wrongusername
  • 18,564
  • 40
  • 130
  • 214
2
votes
0 answers

Selenium-webdriver zip issue

Yesterday my rspec +selenium was running fine. Today when i ran tests i got: Failure/Error: Unable to find matching line from backtrace NameError: uninitialized constant Zip::File #…
Adam Piotrowski
  • 674
  • 1
  • 7
  • 15
2
votes
1 answer

Use rubyzip to download paperclip attachments within nested model

I have the following model setup: assignments belong to a user and assignments have many submissions submissions belong to users and also belong to assignments submissions have attached files (using paperclip). I want the assignment user (creator)…
SOConnell
  • 793
  • 1
  • 8
  • 27
2
votes
1 answer

how to split/rejoin the zip file using ruby

i am new to Ruby. Is there any way to split a large zip file & then again join the split files to one large zip file? i can see a link with split sample, but can see an error while running(split object error) split sample link Can anyone help me in…
Dheeraj Gundra
  • 1,585
  • 2
  • 10
  • 9
2
votes
3 answers

How can I copy a directory inside a zip archive to a second zip archive using rubyzip?

I have a .zip archive containing several directories. Using the rubyzip gem I would like to reach into the .zip archive, copy a specified directory (and its contents) and move the directory into a second .zip archive. Ideally I would not have to…
rswolff
  • 3,258
  • 5
  • 28
  • 31