php gzseek似乎超出了文件的大小

问题描述

在过去两年中,我在尝试确定文件(尤其是gz zip压缩文件)的大小时遇到​​了一个奇怪的问题。我找到了解决方法,但它们并不理想。问题在于,gzseek()似乎总是寻找最多。不管未压缩文件的大小如何,文件大小均为2.14GB。 在测试时,我通过以下两种方式建立了未压缩文件的大小:1)解压缩并另存为文本,以及2)使用gzread()每次读取1MB直到文件结束。假设未压缩的文件大小为13MB。

使用gzseek()和gztell()测试代码。这将使句柄前进1mb / 1000000字节,但始终继续到大约。 2.14GB,无论未压缩的文件大小如何:

//GZ file is opened ....

gzseek($Handle,SEEK_SET);
while (true) {
  //Seek through file advancing offset with 1000000 bytes each time
  $Eof  = gzseek($Handle,1000000,SEEK_CUR);  //0 or -1 if passed eof

  //This will dump the handle position incrementing 1000000 bytes at the time but continue until
  //approx. 2.14 GB even through file is 13MB uncompressed
  var_dump(gztell($Handle)); 

  //When the handle (via gztell() ) shows 2.14GB,the gzseek() returns -1 which means it 
  //has reached / gone pas end of file
  if ( $Eof !== -1 ) {
     //This will only be true once the gztell() shows approx. 2.14GB
     break;
  } 

}

现在,如果改为使用gzread()可以正常工作,则将句柄前进1mb / 1000000字节,直到13mb。例如:

while ( !gzeof($Handle) ) {
   $Data = gzread($Handle,1000000);
}

在过去几年中对此进行了大量研究,但我从未找到一种可行的解决方案来测量gz文件的文件大小,也没有找到关于为什么无法使用gzseek完成该问题的任何报告,我觉得有些奇怪。 gzseek无法正常工作,我希望可以找到报告的报告,或者我真的在这里遗漏了一些东西。感谢您的帮助,克里斯

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)