The application can provide an open, readable stream; in this case it will be read during the call to Save()()() or one of its overloads.
In cases where a large number of streams will be added to the ZipFile, the application may wish to avoid maintaining all of the streams open simultaneously. To handle this situation, the application should use the AddEntry(String, OpenDelegate, CloseDelegate) overload.
For ZipFile properties including Encryption, Password, SetCompression, ProvisionalAlternateEncoding, ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.
This example adds a single entry to a ZipFile via a Stream.
String zipToCreate = "Content.zip"; String fileNameInArchive = "Content-From-Stream.bin"; using (System.IO.Stream streamToRead = MyStreamOpener()) { using (ZipFile zip = new ZipFile()) { ZipEntry entry= zip.AddEntry(fileNameInArchive, streamToRead); zip.AddFile("Readme.txt"); zip.Save(zipToCreate); // the stream is read implicitly here } }
Dim zipToCreate As String = "Content.zip" Dim fileNameInArchive As String = "Content-From-Stream.bin" Using streamToRead as System.IO.Stream = MyStreamOpener() Using zip As ZipFile = New ZipFile() Dim entry as ZipEntry = zip.AddEntry(fileNameInArchive, streamToRead) zip.AddFile("Readme.txt") zip.Save(zipToCreate) '' the stream is read implicitly, here End Using End Using