This class provides an alternative programming model for reading zip files to the one enabled by the ZipFile class. Use this when reading zip files, as an alternative to the ZipFile class, when you would like to use a Stream class to read the file.
Some application designs require a readable stream for input. This stream can be used to read a zip file, and extract entries.
Both the ZipInputStream
class and the ZipFile
class can be used to read and extract zip files. Both of them support many of the common zip features, including Unicode, different compression levels, and ZIP64. The programming models differ. For example, when extracting entries via calls to the GetNextEntry()
and Read()
methods on the ZipInputStream
class, the caller is responsible for creating the file, writing the bytes into the file, setting the attributes on the file, and setting the created, last modified, and last accessed timestamps on the file. All of these things are done automatically by a call to ZipInputStream
is generally recommended for when your application wants to extract the data, without storing that data into a file.
Aside from the obvious differences in programming model, there are some differences in capability between the ZipFile
class and the ZipInputStream
class.
ZipFile
can be used to create or update zip files, or read and extract zip files. ZipInputStream
can be used only to read and extract zip files. If you want to use a stream to create zip files, check out the ZipOutputStream. ZipInputStream
cannot read segmented or spanned zip files. ZipInputStream
will not read Zip file comments. ZipInputStream
will always underperform ZipFile
. This is because the ZipInputStream
does a full scan on the zip file, while the ZipFile
class reads the central directory of the zip file.