![](/img/trans.png)
[英]Reading zlib/gzip compressed data from MS SQL Server using Python
[英]How to unzip 'gzip compressed data, from FAT filesystem (MS-DOS, OS/2, NT),' using Python
我正在尝试使用 Python 解压缩从 iCloud.com 下载的存档文件。 众所周知的方法都不起作用。 我用 Python 3 尝试了以下操作:
shutil.unpack_archive()
gzip
库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
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.