简体   繁体   English

rubyzip 文件顺序

[英]rubyzip file order

I am making an archive for a directory, where each file has a name with 3 digits starting from 001 to 049. My code is the following:我正在为一个目录创建一个存档,其中每个文件都有一个从 001 到 049 的 3 位数字的名称。我的代码如下:

Zip::ZipFile.open(File.join(out, dir+".cbz"), Zip::ZipFile::CREATE) {
  |zipfile|
  Dir.glob(File.join(dir, "*")).sort.each {
    |file|
    puts "add file #{file}"
    zipfile.add(File.basename(file),file)
  }
}

When adding the files, I verified with puts that they are added in numerically ascending order.添加文件时,我用puts验证了它们是按数字升序添加的。 But when I try to decompress them with zip , I found that they are decompressed in a random order (eg. 045, 002, ...).但是当我尝试使用zip解压缩它们时,我发现它们是按随机顺序解压的(例如 045、002、...)。

How can I ensure that they decompress in the numerical order?如何确保它们按数字顺序解压?

Edit: Taking a look at the produced zip file with a hex editor shows that the images are added in no sensible order, but that they are extracted via unzip in the order they a present in the central directory (block at the end of the zip file).编辑:使用十六进制编辑器查看生成的 zip 文件显示图像以不合理的顺序添加,但它们是通过unzip按照它们在中央目录中出现的顺序提取的(块在 zip 末尾文件)。

I have traced this to an issue in the rubyzip library, whereby the entries array was not being sorted prior to being written to the central directory, but unzip was dependent on this order.我已经将此追溯到 rubyzip 库中的一个问题,即条目数组在写入中央目录之前没有被排序,但unzip依赖于这个顺序。

Fixed, and sent a pull request upstream.已修复,并向上游发送了拉取请求。

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

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