PartialZip is a .NET-Standard library to download specific files from remote .zip archives.
PartialZip is based on libfragmentzip by @tihmstar.
None
Nuget:
PM> Install-Package PartialZip
The remote web server must support HTTP range requests.
Loading a list of all files in a .zip archive:
IEnumerable<string> fileList = await PartialZipDownloader.GetFileList("https://www.example.com/archive.zip");
Downloading a specific file from a .zip archive:
byte[] fileContent = await PartialZipDownloader.DownloadFile("https://www.example.com/archive.zip", "file.txt");
- PartialZip sends a HTTP
HEAD
request to the archive url to retrieve theContent-Length
andAccept-Range
Header.- If the web server does not support byte range requests, an exception is thrown.
- PartialZip uses the content length to get the
End Of Central Directory
record. If certain values reach their maximum limit, PartialZip can determine if it is a ZIP64 file.- If it is a ZIP64 file, PartialZip gets the
ZIP64 End Of Central Directory Locator
right before theEnd Of Central Directory
. - With the locator, PartialZip can compute the byte ranges for the
ZIP64 End Of Central Directory
- If it is a ZIP64 file, PartialZip gets the
- The
(ZIP64) End Of Central Directory
record tells PartialZip the start of theCentral Directory
, its size and its element count. - Now, PartialZip can get the
Central Directory
containing the filenames, sizes and offsets for all files in the archive. - To download a specific file, PartialZip gets the
Central Directory
record for the file to compute the byte ranges for theLocal File Header
of the file. TheLocal File Header
contains information about the compression and other values used to compute the start offset of the file data. - PartialZip can now download the byte range for the file data and inflate it in case of
Deflate
compression.
Further reading: .ZIP File Format Specification by PKWARE Inc.