This class provides an alternative programming model to the one enabled by the ZipFile class. Use this when creating zip files, as an alternative to the ZipFile class, when you would like to use a Stream class to write the zip file.
Some designs require a writable stream for output. This stream can be used to produce a zip file, as it is written.
Both the ZipOutputStream
class and the ZipFile
class can be used to create zip files. Both of them support many of the common zip features, including Unicode, different compression levels, and ZIP64. For example, when creating a zip file via calls to the PutNextEntry()
and Write()
methods on the ZipOutputStream
class, the caller is responsible for opening the file, reading the bytes from the file, writing those bytes into the ZipOutputStream
, setting the attributes on the ZipEntry
, and setting the created, last modified, and last accessed timestamps on the zip entry. All of these things are done automatically by a call to ZipOutputStream
is generally recommended for when your application wants to emit the arbitrary data, not necessarily data from a filesystem file, directly into a zip file.
Aside from the differences in programming model, there are other differences in capability between the two classes.
ZipFile
can be used to read and extract zip files, in addition to creating zip files. ZipOutputStream
cannot read zip files. If you want to use a stream to read zip files, check out the ZipInputStream class. ZipOutputStream
does not support the creation of segmented or spanned zip files. ZipOutputStream
cannot produce a self-extracting archive.