Ionic Zip Library v1.9.1.6
ZipOutputStream Constructor (fileName)
Reference ► Ionic.Zip ► ZipOutputStream ► ZipOutputStream(String)
Create a ZipOutputStream that writes to a filesystem file.
Declaration Syntax
Parameters
- fileName (String)
- The name of the zip file to create.
Remarks
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