ZipOutputStream Constructor (stream)

DotNetZip

Ionic Zip Library v1.9.1.6 ZipOutputStream Constructor (stream)
ReferenceIonic.ZipZipOutputStreamZipOutputStream(Stream)
Create a ZipOutputStream, wrapping an existing stream.
Declaration Syntax
C# Visual Basic Visual C++
public ZipOutputStream(
	Stream stream
)
Public Sub New ( _
	stream As Stream _
)
public:
ZipOutputStream(
	Stream^ stream
)
Parameters
stream (Stream)
The stream to wrap. It must be writable. This stream will be closed at the time the ZipOutputStream is closed.
Remarks

The ZipFile class is generally easier to use when creating zip files. The ZipOutputStream offers a different metaphor for creating a zip file, based on the Stream class.

Examples
This example shows how to create a zip file, using the ZipOutputStream class.
CopyC#
private void Zipup()
{
    if (filesToZip.Count == 0)
    {
        System.Console.WriteLine("Nothing to do.");
        return;
    }

    using (var raw = File.Open(_outputFileName, FileMode.Create, FileAccess.ReadWrite ))
    {
        using (var output= new ZipOutputStream(raw))
        {
            output.Password = "VerySecret!";
            output.Encryption = EncryptionAlgorithm.WinZipAes256;

            foreach (string inputFileName in filesToZip)
            {
                System.Console.WriteLine("file: {0}", inputFileName);

                output.PutNextEntry(inputFileName);
                using (var input = File.Open(inputFileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Write ))
                {
                    byte[] buffer= new byte[2048];
                    int n;
                    while ((n= input.Read(buffer,0,buffer.Length)) > 0)
                    {
                        output.Write(buffer,0,n);
                    }
                }
            }
        }
    }
}
CopyVB.NET
Private Sub Zipup()
    Dim outputFileName As String = "XmlData.zip"
    Dim filesToZip As String() = Directory.GetFiles(".", "*.xml")
    If (filesToZip.Length = 0) Then
        Console.WriteLine("Nothing to do.")
    Else
        Using raw As FileStream = File.Open(outputFileName, FileMode.Create, FileAccess.ReadWrite)
            Using output As ZipOutputStream = New ZipOutputStream(raw)
                output.Password = "VerySecret!"
                output.Encryption = EncryptionAlgorithm.WinZipAes256
                Dim inputFileName As String
                For Each inputFileName In filesToZip
                    Console.WriteLine("file: {0}", inputFileName)
                    output.PutNextEntry(inputFileName)
                    Using input As FileStream = File.Open(inputFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
                        Dim n As Integer
                        Dim buffer As Byte() = New Byte(2048) {}
                        Do While (n = input.Read(buffer, 0, buffer.Length) > 0)
                            output.Write(buffer, 0, n)
                        Loop
                    End Using
                Next
            End Using
        End Using
    End If
End Sub

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