Imports System.IO
Imports Xceed.Zip.ReaderWriter
Using fileStream1 As New FileStream("d:\testOutput\test.zip",
FileMode.Open, FileAccess.Read)
'Must seek to the beginning of the stream before reading.
fileStream1.Seek(0, SeekOrigin.Begin)
'Create a ZipReader around the stream.
Dim zipReader1 As New Xceed.Zip.ReaderWriter.ZipReader(fileStream1)
'Subscribe to the ByteProgression event
AddHandler zipReader1.ByteProgression, AddressOf Of
ZipReaderByteProgressionEventArgs
'Subscribe to the InvalidPassword event
AddHandler zipReader1.InvalidPassword, AddressOf Of
ZipReaderInvalidPasswordEventArgs
Dim zipItemLocalHeader As ZipItemLocalHeader = Nothing
'Read the local headers until no more are found
Do While Not (zipItemLocalHeader = zipReader1.ReadItemLocalHeader()) Is
Nothing
Dim buffer As Byte() = New Byte(1023){}
Dim read As Integer = 0
'Read the item's data
Do While (read = zipReader1.ReadItemData(buffer, 0, buffer.Length)) > 0
'Do something with the data in 'buffer'
Loop
Loop
End Using
'The InvalidPassword event's handler. Demonstrates the use of
'the properties of ZipReaderInvalidPasswordEventArgs.
Shared Sub zipReader1_InvalidPassword(ByVal sender As Object, ByVal e As
ZipReaderInvalidPasswordEventArgs)
Console.Write("Enter password for file {0} (<Enter> alone to abort): ",
e.ZipItemLocalHeader.FileName)
Dim password As String = Console.ReadLine()
'Set Abort to true to abort the read operation.
If String.IsNullOrEmpty(password) Then
e.Abort = True
Else
'Set NewPassword to the provided password. If it is the correct password,
'the read operation will proceed. Otherwise, the InvalidPassword event is
'raised again.
e.NewPassword = password
End If
End Sub
'The ByteProgression event's handler. Demonstrates the use of
'the properties of ZipReaderByteProgressionEventArgs.
Shared Sub zipReader1_ByteProgression(ByVal sender As Object, ByVal e As
ZipReaderByteProgressionEventArgs)
If e.UncompressedSize = -1 Then
Console.WriteLine("Processing item {0}: {1} bytes processed.",
e.ZipItemLocalHeader.FileName, e.BytesProcessed)
Else
'UncompressedSize is not -1, so this property and the Percent
'property return useful values.
Console.WriteLine("Processing item {0}: {1} bytes processed
({3}%). (Uncompressed size = {3}.)",
e.ZipItemLocalHeader.FileName,
e.BytesProcessed, e.UncompressedSize, e.Percent)
End If
End Sub