I am trying to unzip this archive file downloaded from iCloud.com using Python. None of the well-known methods work. I tried the following with Python 3:
- using
shutil.unpack_archive()
- using Python's
gzip
library - using Python's
zipfile
library
When I inspected the file with Python's magic
library and xxd
tool, it shows following output:
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
What's so special about a zip file created on FAT? How to unpack it?
CodePudding user response:
As your question title suggests, it's not a zip file (despite the .zip
filetype); it's a gzip file. Try using the gzip
module:
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
prints:
20210129_201905366.band.zip is a zip file: False
20210129_201905366.band.zip is a gzip file with length: 6670928
It turned out to be a zip
file (20210129_201905366.band
) inside gzip
file (20210129_201905366.band.zip
).