Question

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 SPlit/join the zip filesin ruby?

Was it helpful?

Solution

The Zip::ZipFile.split isn't available in the latest rubyzip version 0.9.9. It exists only in the latest master branch of the source code. If you're finding a way to split a large file into small parts and join them later, or rather, you don't rely on the intermediate split results, you can try split of Unix/Linux. E.g. you want to use a USB drive to copy the small files and join them in another computer.

# each file will contain 1048576 bytes
# the file will be splitted into xaa, xab, xac...
# You can add optional prefix to the end of the command
split -b 1048576 large_input_file.zip

# join them some where after
cat x* >large_input_file.zip

The rubyzip gem provides a way to create multi-part zip files from a large zip file. You can use p7zip or WinRAR to unzip the split zip file parts. However, it's strange that unzip doesn't support multi-part zip files. The manual of unzip says,

Multi-part archives are not yet supported, except in conjunction with zip. (All parts must be concatenated together in order, and then zip -F'' (for zip 2.x) orzip -FF'' (for zip 3.x) must be performed on the concatenated archive in order to fix'' it. Also, zip 3.0 and later can combine multi-part (split) archives into a combined single-file archive usingzip -s- inarchive -O outarchive''. See the zip 3 manual page for more information.) This will definitely be corrected in the next major release.

If you want this, you can clone the latest master branch and use that lib to do the job.

$ git clone https://github.com/aussiegeek/rubyzip.git
$ vim split.rb

Then in your ruby file "split.rb":

$:.unshift './rubyzip/lib'

require 'zip/zip'

part_zip_count = Zip::ZipFile.split("large_zip_file.zip", 102400, false)
puts "Zip file splitted in #{part_zip_count} parts"

You can checkout the docs for split

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top