Generalizing untar data to also work with zips

Here is what I am currently using when I want to unzip something:

from zipfile import ZipFile

url = "https://github.com/karoldvl/ESC-50/archive/master.zip"

def zip_extract(fname, dest):
    zipfile.ZipFile(fname, mode='r').extractall(dest)

path = untar_data(url, extract_func=zip_extract)
6 Likes