Skip to content

PartialZip is a .NET-Standard library to download specific files from remote .zip archives.

License

Notifications You must be signed in to change notification settings

Jan-Kruse/PartialZip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PartialZip

License: LGPL v3 Nuget

PartialZip is a .NET-Standard library to download specific files from remote .zip archives.

PartialZip is based on libfragmentzip by @tihmstar.

External Dependencies

None

Installation

Nuget:

PM> Install-Package PartialZip

Usage

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");

How it works

  • PartialZip sends a HTTP HEAD request to the archive url to retrieve the Content-Length and Accept-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 the End Of Central Directory.
    • With the locator, PartialZip can compute the byte ranges for the ZIP64 End Of Central Directory
  • The (ZIP64) End Of Central Directory record tells PartialZip the start of the Central 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 the Local File Header of the file. The Local 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.

Credits

@tihmstar for libfragmentzip

Contributors

BuIlDaLiBlE

About

PartialZip is a .NET-Standard library to download specific files from remote .zip archives.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages