AddEntry Method (entryName, stream)

DotNetZip

Ionic Zip Library v1.9.1.6 AddEntry Method (entryName, stream)
ReferenceIonic.ZipZipFileAddEntry(String, Stream)
Create an entry in the ZipFile using the given Stream as input. The entry will have the given filename.
Declaration Syntax
C# Visual Basic Visual C++
public ZipEntry AddEntry(
	string entryName,
	Stream stream
)
Public Function AddEntry ( _
	entryName As String, _
	stream As Stream _
) As ZipEntry
public:
ZipEntry^ AddEntry(
	String^ entryName, 
	Stream^ stream
)
Parameters
entryName (String)
The name, including any path, which is shown in the zip file for the added entry.
stream (Stream)
The input stream from which to grab content for the file
Return Value
The ZipEntry added.
Remarks

The application should provide an open, readable stream; in this case it will be read during the call to Save()()()() or one of its overloads.

The passed stream will be read from its current position. If necessary, callers should set the position in the stream before calling AddEntry(). This might be appropriate when using this method with a MemoryStream, for example.

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.

Examples

This example adds a single entry to a ZipFile via a Stream.

CopyC#
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
  }
}
CopyVB.NET
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

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)