'Is it possible to download just part of a ZIP file using python zipfile library

I was wondering is there any way by which I can download only a part of a .rar or .zip file without downloading the whole file ? There is a zip file containing files A,B,C and D. I only need A. Can I somehow, use zipfile module so that i can only download 1 file ?

i am trying below code:

 r = c.get(file)
    z = ZipFile.ZipFile(BytesIO(r.content)) 
    for file1 in z.namelist():
        if 'time' not in file1:
            print("hi")
            z.extractall(file1,download_path + filename)

This code is downloading whole zip file and only extracting specific one. Can i somehow download only the file i Need. There is similar question here but it shows only approch by command line in linux. That question dosent address how it can be done using python liabraries.



Solution 1:[1]

The question @Juggernaut mentioned in a comment is actually very helpful, as it points you in the direction of the solution.

You need to create a replacement for Bytes.IO that returns the necessary information to ZipFile. You will need to get the length of the file, and then get whatever sections ZipFile asks for.

How large are those file? Is it really worth the trouble?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zmbq