简体   繁体   English

如何使用ruby分割/重新合并zip文件

[英]how to split/rejoin the zip file using ruby

i am new to Ruby. 我是Ruby的新手。 Is there any way to split a large zip file & then again join the split files to one large zip file? 有什么方法可以分割一个大的zip文件,然后再次将分割后的文件加入一个大的zip文件中?

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? 有人可以帮我拆分/加入ruby中的zip文件吗?

The Zip::ZipFile.split isn't available in the latest rubyzip version 0.9.9. Zip::ZipFile.split在最新的rubyzip版本0.9.9中不可用。 It exists only in the latest master branch of the source code. 它仅存在于源代码的最新master分支中。 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. 如果您找到一种将大文件拆分为小部分并在以后加入的方法,或者您不依赖中间的拆分结果,则可以尝试Unix / Linux的split Eg you want to use a USB drive to copy the small files and join them in another computer. 例如,您要使用USB驱动器复制小文件并将它们加入另一台计算机。

# 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. rubyzip gem提供了一种从大型zip文件创建多部分zip文件的方法。 You can use p7zip or WinRAR to unzip the split zip file parts. 您可以使用p7zipWinRAR解压缩拆分的zip文件部分。 However, it's strange that unzip doesn't support multi-part zip files. 但是,奇怪的是, unzip不支持多部分zip文件。 The manual of unzip says, unzip手册说:

Multi-part archives are not yet supported, except in conjunction with zip. 除与zip结合使用外,尚不支持多部分归档。 (All parts must be concatenated together in order, and then zip -F'' (for zip 2.x) or zip -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 using zip -s- inarchive -O outarchive''. See the zip 3 manual page for more information.) This will definitely be corrected in the next major release. (所有零件必须按顺序串联在一起,然后必须在串联的归档文件上执行zip -F'' (for zip 2.x) or zip -FF''(对于zip 3.x)才能fix'' it. Also, zip 3.0 and later can combine multi-part (split) archives into a combined single-file archive using zip -s- inarchive -O outarchive fix'' it. Also, zip 3.0 and later can combine multi-part (split) archives into a combined single-file archive using 。在下一个主要版本中予以更正。

If you want this, you can clone the latest master branch and use that lib to do the job. 如果需要,可以克隆最新的master分支,并使用该lib来完成这项工作。

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

Then in your ruby file "split.rb": 然后在您的红宝石文件“ 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 您可以签出文档进行拆分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM