rubyzip 文件顺序
我正在为一个目录制作存档,其中每个文件都有一个从 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)
}
}
添加文件时,我使用 puts
验证它们是否已添加按数字升序排列。 但是当我尝试使用 zip
解压缩它们时,我发现它们是以随机顺序解压缩的(例如 045、002,...)。
如何确保它们按数字顺序解压?
编辑:使用十六进制编辑器查看生成的 zip 文件,发现图像的添加顺序不合理,但它们是通过 unzip
按照它们在中央目录中出现的顺序提取的( zip 文件末尾的块)。
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:
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.
But when I try to decompress them with zip
, I found that they are decompressed in a random order (eg. 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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已将此问题追溯到 rubyzip 库中的一个问题,即条目数组在写入中央目录之前未进行排序,但
unzip
依赖于此顺序。已修复,并向上游发送了拉取请求。
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.Fixed, and sent a pull request upstream.