如何使用 Python 解压缩'gzip compressed data, from FAT filesystem (MS-DOS, OS/2, NT),'



我正在尝试使用Python解压缩从iCloud.com下载的此存档文件。这些众所周知的方法都不起作用。我在Python 3中尝试了以下操作:

  1. 使用shutil.unpack_archive()
  2. 使用Python的gzip库使用Python的zipfile

当我用Python的magic库和xxd工具检查文件时,它显示以下输出:

magic.from_file()=>'gzip compressed data, from FAT filesystem (MS-DOS, OS/2, NT), original size modulo 2^32 6670928'

xxd -l 4 ...=>1f8b 0800

在FAT上创建的zip文件有什么特别之处?如何打开包装?

正如您的问题标题所示,它不是zip文件(尽管.zip文件类型);这是一个gzip文件。尝试使用gzip模块:

import zipfile
FN = "20210129_201905366.band.zip"
print(f"{FN} is a zip file: {zipfile.is_zipfile(FN)}")
import gzip
GZ = gzip.GzipFile(FN)
contents = GZ.read()
print(f"{FN} is a gzip file with length: {len(contents)}")
with open('ungzipped.zip', 'wb') as i:
i.write(contents)
import shutil
shutil.unpack_archive('ungzipped.zip')
# This produces correct output file - 20210129_201905366.band

打印:

20210129_201905366.band.zip is a zip file: False
20210129_201905366.band.zip is a gzip file with length: 6670928

原来是gzip文件(20210129_201905366.band.zip)中的zip文件(20210129_201905366.band)。