Ionic Zip Library v1.9.1.6
ZipInputStream Constructor (fileName)
Reference ► Ionic.Zip ► ZipInputStream ► ZipInputStream(String)
Create a ZipInputStream, given the name of an existing zip file.
Declaration Syntax
Parameters
- fileName (String)
- The name of the filesystem file to read.
Remarks
This constructor opens a FileStream for the given zipfile, and wraps a ZipInputStream around that. See the documentation for the ZipInputStream(Stream) constructor for full details.
While the ZipFile class is generally easier to use, this class provides an alternative to those applications that want to read from a zipfile directly, using a Stream.
Examples
This example shows how to read a zip file, and extract entries, using the
ZipInputStream class.
CopyC#
private void Unzip() { byte[] buffer= new byte[2048]; int n; using (var input= new ZipInputStream(inputFileName)) { ZipEntry e; while (( e = input.GetNextEntry()) != null) { if (e.IsDirectory) continue; string outputPath = Path.Combine(extractDir, e.FileName); using (var output = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite)) { while ((n= input.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer,0,n); } } } } }
CopyVB.NET
Private Sub UnZip() Dim inputFileName As String = "MyArchive.zip" Dim extractDir As String = "extract" Dim buffer As Byte() = New Byte(2048) {} Using input As ZipInputStream = New ZipInputStream(inputFileName) Dim e As ZipEntry Do While (Not e = input.GetNextEntry Is Nothing) If Not e.IsDirectory Then Using output As FileStream = File.Open(Path.Combine(extractDir, e.FileName), _ FileMode.Create, FileAccess.ReadWrite) Dim n As Integer Do While (n = input.Read(buffer, 0, buffer.Length) > 0) output.Write(buffer, 0, n) Loop End Using End If Loop End Using End Sub