Python 3.10.6 - Trying to use zipfile to extract from zip with outdated header

Viewed 35

I'm working with the following block of code, in an attempt to extract data from a zip file

import zipfile

def get_zip(filenam,targetdir):
    with zipfile.ZipFile(filenam,"r") as zip_ref:
        zip_ref.extractall(targetdir)

zip_file = 'coolThing.zip'
targetdir = 'C:/puItHere/'
get_zip(zip_file,targetdir)

However, I get the error

"BadZipFile: Bad magic number for file header"

Looking through previous forums like this one, I find that my zip file needs to have the header "\x50\x4B\x03\x04" but it actually has the header "b'PK\x03\x04"

Does anyone know of a way where I can use zipfile, pyunpack, or any other library in order to extract what I need from this file type? I'm getting data from a large repository, and will be iterating through 30 TB of data, only taking what I need out of the zip files, and so far from what I've seen, they all use the same header

Thanks!

0 Answers
Related