在python中打开损坏的.tgz

时间:2014-02-18 11:40:43

标签: python tar unzip ioerror

我应该在output.tgz archive

中解压缩RESULT文件夹
#!/usr/bin/python
import os, sys, tarfile, gzip


    def unZip(self,file, filename,dire):  
        tar = tarfile.open(filename,"r:gz")
        for file in tar.getmembers():
       if file.name.startswith("RESULT"):
               tar.extract(file,dire)
               print 'Done.'



def main():
    utilities = ZipUtil()
    filename = 'output.tgz'
    directory = str(sys.argv[1]);
    path = os.path.join(directory, filename)
    utilities.unZip(directory,path,directory)

    main()

我收到此错误

  File "/usr/lib64/python2.7/tarfile.py", line 1805, in getmembers
    self._load()        # all members, we first have to
  File "/usr/lib64/python2.7/tarfile.py", line 2380, in _load
    tarinfo = self.next()
  File "/usr/lib64/python2.7/tarfile.py", line 2315, in next
    self.fileobj.seek(self.offset)
  File "/usr/lib64/python2.7/gzip.py", line 429, in seek
    self.read(1024)
  File "/usr/lib64/python2.7/gzip.py", line 256, in read
    self._read(readsize)
  File "/usr/lib64/python2.7/gzip.py", line 303, in _read
    self._read_eof()
  File "/usr/lib64/python2.7/gzip.py", line 342, in _read_eof
    hex(self.crc)))
IOError: CRC check failed 0xccf8af55 != 0x43cb4d43L

有很多这样的问题,但现在仍然可以解决这个问题。文件output.tgz已下载,它可能已损坏,这就是为什么我猜它不起作用。但无论如何都要告诉焦油打开它。太多了!

0 个答案:

没有答案