ZipOutputStream Constructor (fileName)

DotNetZip

Ionic Zip Library v1.9.1.6 ZipOutputStream Constructor (fileName)
ReferenceIonic.ZipZipOutputStreamZipOutputStream(String)
Create a ZipOutputStream that writes to a filesystem file.
Declaration Syntax
C# Visual Basic Visual C++
public ZipOutputStream(
	string fileName
)
Public Sub New ( _
	fileName As String _
)
public:
ZipOutputStream(
	String^ fileName
)
Parameters
fileName (String)
The name of the zip file to create.
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 output= new ZipOutputStream(outputFileName))
    {
        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 output As ZipOutputStream = New ZipOutputStream(outputFileName)
            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 If
End Sub

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