Zip文件读取:有没有办法找到正确大小的文件> 4GB的非Zip64 zip文件?

时间:2014-03-20 18:28:54

标签: ruby zip tcl unzip

我使用这个tcl代码在64位Ubuntu机器上构建zip文件 没有Zip64扩展(请参阅man zip(1)以获得解释):

以下是我使用ActiveTcl 8.6(称为buildzip.tcl)构建这样一个zip文件的方法:

package require zlibtcl
package require zipfile::encode

set z [zipfile::encode Z]
set i 0
set outName out.zip
set force 0
while { $i < $argc } {
    set arg [lindex $argv $i] 
    switch -glob -- $arg {
        -o {
            set i [expr {$i + 1}]
            set outName [lindex $argv $i]
        }
        -f {
            set force 1
        }
        -* {
            puts {Usage buildzip.tcl [-f: force overwrite] [-o zipfile|out.zip] file...}
            exit
        }
        default {
            $z file: $arg 0 ./arg
        }
    }
    set i [expr {$i + 1}]
}
if { [file exists $outName] == 1 && $force == 0 } {
    puts "File $outName exists, use -f to overwrite"
    exit
}
$z write $outName
$z destroy

让我们创建2个大文件:

dd if=/dev/zero bs=1 count=0 seek=3G of=bigfile.dat
dd if=/dev/zero bs=1 count=0 seek=5G of=bigfile2.dat

让我们看看它们有多大:

-rw-r--r-- 1 eric eric 5,368,709,120 Mar 20 11:14 bigfile2.dat
-rw-r--r-- 1 eric eric 3,221,225,472 Mar 20 11:14 bigfile.dat

让我们拉上它们:

$ tclsh buildzip.tcl -f -o foo.zip bigfile{,2}.dat 

拉链认为它们的尺寸是多少?

$ unzip -l out.zip 
Archive:  out.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
3221225472  2014-03-20 11:14   bigfile.dat
1073741824  2014-03-20 11:14   bigfile2.dat
---------                     -------
4294967296                     2 files

但是,如果我解压缩它们,我会收回原始内容:

$ rm bigfile*; unzip out.zip ; L bigfil*
Archive:  out.zip
  inflating: bigfile.dat             
  inflating: bigfile2.dat            
-rw-r--r-- 1 eric eric 5,368,709,120 Mar 20 11:14 bigfile2.dat
-rw-r--r-- 1 eric eric 3,221,225,472 Mar 20 11:14 bigfile.dat

数字&#34; 1073741824&#34;更好地称为0x40000000或1GB。 我还没看过ziplib C代码,但我猜不出来 1GB是一个“不可能”的哨兵&#34;值,看看这段代码如何 可以追溯到1000美元20MB硬盘的日子,没有服用 考虑摩尔定律。

我的问题:我可以在没有的情况下发现每个条目的真实大小 不得不实际提取它?最好是纯Ruby? 解压缩显然可以求助于其提取的其他东西 完整的文件,而不是它的第一个1GB。

1 个答案:

答案 0 :(得分:0)

甚至不使用该目录。尺寸值是实际尺寸mod 4GB, 所以它不可靠。而是使用Ruby Zip :: InputStream的界面, 并且一次读取8MB这样的东西,并在我们读得太多时纾困。

啊,溢出。