Imports System.IO
Imports Xceed.Zip.ReaderWriter
'The target Zip archive.
Using fileStream1 As New FileStream("d:\testOutput\test.zip",
FileMode.Create, FileAccess.Write)
'Create a ZipWriter object around the stream.
Dim zipWriter1 As New Xceed.Zip.ReaderWriter.ZipWriter(fileStream1)
'Subscribe to the ByteProgression event.
AddHandler zipWriter1.ByteProgression, AddressOf Of
ZipWriterByteProgressionEventArgs
Dim directoryInfo As New DirectoryInfo("d:\test\")
If directoryInfo.Exists Then
Dim files As FileInfo() = directoryInfo.GetFiles("*.*",
SearchOption.AllDirectories)
For Each file As FileInfo In files
'Create ZipItemLocalHeader for current item and write to archive.
Dim zipItemLocalHeader1 As New ZipItemLocalHeader(file.Name)
zipWriter1.WriteItemLocalHeader(zipItemLocalHeader1)
Dim buffer As Byte() = New Byte(1023){}
Dim read As Integer = 0
Using fs As FileStream = file.OpenRead()
'Read the current item's data
read = fs.Read(buffer, 0, buffer.Length)
Do While (read <> 0)
'Write the current item's data to the Zip archive
zipWriter1.WriteItemData(buffer, 0, read)
read = fs.Read(buffer, 0, buffer.Length)
Loop
End Using
Next file
'Close the Zip archive
zipWriter1.CloseZipFile()
Console.WriteLine("Zip archive created.")
End If
End Using
'The ByteProgression event's handler. Demonstrates the use of
'the properties of ZipWriterByteProgressionEventArgs.
Shared Sub zipWriter1_ByteProgression(ByVal sender As Object, ByVal e As ZipWriterByteProgressionEventArgs)
Console.WriteLine("Item {0}: CompressionMethod = {1},
CompressionLevel = {2}.", e.ZipItemLocalHeader.FileName,
e.ZipItemLocalHeader.CompressionMethod,
e.ZipItemLocalHeader.CompressionLevel)
End Sub