Is it possible to download just part of a ZIP archive (e.g. one file)?

前端 未结 7 612
时光说笑
时光说笑 2020-12-14 17:51

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 a

相关标签:
7条回答
  • 2020-12-14 18:30

    You can use FDM, it's support Zip files partial download: Free Download Manager lets you download only the necessary part of a zip file.

    http://www.freedownloadmanager.org/features.htm

    0 讨论(0)
  • 2020-12-14 18:39

    In a way, yes, you can.

    ZIP file format says that there's a "central directory". Basically, this is a table that stores what files are in the archive and what offsets do they have.

    So, using Content-Range you could download part of file from the end (central directory is the last thing in zip file) and try to identify central directory in it. If you succeed then you know file list and offsets, so you can proceed and get those chunks separately and decompress them yourself.

    This approach is quite error-prone and is not guaranteed to work. But so is hacking in general :-)

    Another possible approach would be to build a custom server for that (see @pst's answer for more details).

    0 讨论(0)
  • 2020-12-14 18:40

    Instead, use Google Docs's reader. Goto this link- https://docs.google.com/viewer?url=http://file.zip and change the address of zip file. It can open both zip and rar files

    0 讨论(0)
  • 2020-12-14 18:45

    There are several ways for a normal person to be able to download an individual file from a compressed ZIP file, unfortunately they aren't common knowledge. There are some open-source tools and online web services, including:

    • Windows: Iczelion's HTTP Zip Dowloader (open-source) (that I've used for over 10 years!)
    • Linux: partial-zip (open-source)
    • Online: wobzip.org (closed-source)
    0 讨论(0)
  • 2020-12-14 18:45

    Can you arrange for your file to appear in the back of the zip?

    Download 100k:

    $ curl -r -100000 https://www.keepassx.org/releases/2.0.2/KeePassX-2.0.2.zip -o tail.zip
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
    100   97k  100   97k    0     0  84739      0  0:00:01  0:00:01 --:--:-- 84817
    

    Check what files we did get:

    $ unzip -t tail.zip
      (please check that you have transferred or created the zipfile in the
      appropriate BINARY mode and that you have compiled UnZip properly)
    error [tail.zip]:  attempt to seek before beginning of zipfile
      (please check that you have transferred or created the zipfile in the
      appropriate BINARY mode and that you have compiled UnZip properly)
    error [tail.zip]:  attempt to seek before beginning of zipfile
      (please check that you have transferred or created the zipfile in the
      appropriate BINARY mode and that you have compiled UnZip properly)
    error [tail.zip]:  attempt to seek before beginning of zipfile
      (please check that you have transferred or created the zipfile in the
      appropriate BINARY mode and that you have compiled UnZip properly)
    error [tail.zip]:  attempt to seek before beginning of zipfile
      (please check that you have transferred or created the zipfile in the
      appropriate BINARY mode and that you have compiled UnZip properly)
        testing: KeePassX-2.0.2/share/translations/keepassx_uk.qm   OK
        testing: KeePassX-2.0.2/share/translations/keepassx_zh_CN.qm   OK
        testing: KeePassX-2.0.2/share/translations/keepassx_zh_TW.qm   OK
        testing: KeePassX-2.0.2/zlib1.dll   OK
    At least one error was detected in tail.zip.
    

    Then extract the last file:

    $ unzip tail.zip KeePassX-2.0.2/zlib1.dll
    Archive:  tail.zip
    error [tail.zip]:  missing 7751495 bytes in zipfile
      (attempting to process anyway)
      inflating: KeePassX-2.0.2/zlib1.dll  
    
    0 讨论(0)
  • 2020-12-14 18:47

    I think Sergei Tulentsevs idea is brilliant.

    However, if there is control over the server -- e.g. custom code can be deployed -- then it is a rather trivial operation (in the scheme of things :) to map/handle a request, extract the relevant portion of the ZIP archive, and send the data back in the HTTP stream.

    The request might look like:

    http://foo.bar/myfile.zip_a.jpeg
    

    Which would mean extract -- and return -- "a.jpeg" from "myfile.zip".

    (I intentionally chose this silly format so that browsers would likely choose "myfile.zip_a.jpeg" as the name in the download dialog when it appears.)

    Of course, how this is implemented depends on the server/language/framework and there may already be existing solutions that support a similar operation (but I know not).

    Happy coding.

    0 讨论(0)
提交回复
热议问题