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

Using rubyzip error - no such file to load -- zip/zip

I know there is another thread on this subject but I still face this problem even after using all solutions. Is there any other way to generate zip files? Can i use Ubuntu system commands? I did gem install rubyzip I have require…
coredump
  • 714
  • 1
  • 6
  • 16
16
votes
8 answers

rails 3 - LoadError (cannot load such file -- zip/zip)

I'm using rubyzip to zip a csv file so uses can download it. This works perfectly in development mode. But when I tried zipping the file on the production server (rackspace) I received the error: LoadError (cannot load such file -- zip/zip). Is it a…
ggrillone
  • 526
  • 1
  • 6
  • 20
11
votes
1 answer

Stream and unzip large csv file with ruby

I have problem where I need to download, unzip, and then process line by line a very large CSV file. I think it's useful to give you an idea how large the file is: big_file.zip ~700mb big_file.csv ~23gb Here's some things I'd like to…
ZombieDev
  • 959
  • 1
  • 10
  • 25
11
votes
1 answer

rails 3 and rubyzip 1.0.0 uninitialized constant Zip::ZipFile

Im attempting to open a docx file and write back into it using rubyzip 1.0.0 and rails 3. In my gemfile I have: gem 'rubyzip' and the code i'm running is; module Look class Generator def initialize(item) doc =…
mvanio
  • 505
  • 3
  • 15
10
votes
2 answers

Creating multiple csv-files and download all in one zip-archive using rails

I am looking for a way to create multiple csv files and download them as one zip archive within one request in my rails application. To build the archive I use rubyzip gem - to download it just the rails built-in function send_data. The problem I…
floriansuchan
  • 255
  • 4
  • 13
9
votes
3 answers

How can I avoid "Zip end of central directory signature not found (Zip::Error)" with rubyzip?

I'm reading a lot of zip file with rubyzip. However this error message is always showing in only specific file even it is zip file. /app/vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/lib/zip/central_directory.rb:143:in `get_e_o_c_d': Zip end of…
T.Akashi
  • 1,201
  • 1
  • 13
  • 17
9
votes
3 answers

ruby on rails roo gem cannot load zip/zipfilesystem

I am attempting to use the roo gem to process .xlsx spreadsheets that are uploaded by an outside party. I'm getting the following error: LoadError (cannot load such file -- zip/zipfilesystem): I've found a lot of questions similar to this one (such…
Deranger
  • 177
  • 1
  • 3
  • 8
9
votes
1 answer

Rubyzip: Export zip file directly to S3 without writing tmpfile to disk?

I have this code, which writes a zip file to disk, reads it back, uploads to s3, then deletes the file: compressed_file = some_temp_path Zip::ZipOutputStream.open(compressed_file) do |zos| some_file_list.each do |file| …
index
  • 3,697
  • 7
  • 36
  • 55
8
votes
3 answers

How to unzip a zipped folder with rubyzip

I know how to retrieve the contents of a normal zip-file with rubyzip. But i got trouble unzipping the contents of a zipped folder and i hope any of u guys can help me out. this is the code i use to unzip: Zip::ZipFile::open(@file_location) do…
grub4r
  • 133
  • 1
  • 7
8
votes
3 answers

How to edit docx with nokogiri and rubyzip

I'm using a combination of rubyzip and nokogiri to edit a .docx file. I'm using rubyzip to unzip the .docx file and then using nokogiri to parse and change the body of the word/document.xml file but ever time I close rubyzip at the end it corrupts…
8
votes
2 answers

Ruby: Download zip file and extract

I have a ruby script that downloads a remote ZIP file from a server using rubys opencommand. When I look into the downloaded content, it shows something like…
23tux
  • 14,104
  • 15
  • 88
  • 187
7
votes
1 answer

How can I use rubyzip to attach files in a zip archive to an ActiveStorage object Rails 5

I have a model with one attachment that uses ActiveStorage: class ProofreadDocument < ApplicationRecord has_one_attached :file end I am working on a rake task to attach files to a proofread_document. The files are compressed into a zip…
chell
  • 7,646
  • 16
  • 74
  • 140
7
votes
2 answers

How do I get a zipped file's content using the rubyzip library?

I'm trying to extract an uploaded zip file and store its contents in the database, one entry per file. The rubyzip library has nearly no useful documentation. There is an assets table that has key :string (file name) and data :binary (file…
jcoby
  • 4,210
  • 2
  • 29
  • 25
7
votes
4 answers

Using rubyzip to add files and nested directories to a zipoutputstream

I'm struggling with getting rubyzip to append directories to a zipoutputstream. (I want the output stream so I can send it from a rails controller). My code follows this…
fturtle
  • 365
  • 1
  • 5
  • 17
7
votes
1 answer

Zipping a directory recursively & skip container directory

Consider, we have following directory structure: Location: /Users/me/Desktop/directory_to_zip/ dir1 dir2 somefile.txt now, If I use rubyzip to zip the contents of directory_to_zip using the following code: directory =…
CuriousMind
  • 33,537
  • 28
  • 98
  • 137
1
2 3
9 10