Xceed Real-Time Zip for .NET Documentation
Using the ByteProgression event (ZipWriter) - Snippet
The following examples demonstrate how to use ZipWriter's ByteProgression event, as well as its event arguments.
using System.IO;

using Xceed.Zip.ReaderWriter;

//The target Zip archive.

using (FileStream fileStream1 = new FileStream(@"d:\testOutput\test.zip",

  FileMode.Create, FileAccess.Write))

{

  //Create a ZipWriter object around the stream.

  Xceed.Zip.ReaderWriter.ZipWriter zipWriter1 =

    new Xceed.Zip.ReaderWriter.ZipWriter(fileStream1);

  //Subscribe to the ByteProgression event

  zipWriter1.ByteProgression += new

    EventHandler<ZipWriterByteProgressionEventArgs>(zipWriter1_ByteProgression);

  DirectoryInfo directoryInfo = new DirectoryInfo(@"d:\test\");

  if (directoryInfo.Exists)

  {

    FileInfo[] files = directoryInfo.GetFiles("*.*",

      SearchOption.AllDirectories);

    foreach (FileInfo file in files)

    {

      //Create ZipItemLocalHeader for current item and write to archive.

      ZipItemLocalHeader zipItemLocalHeader1 = new ZipItemLocalHeader

        (file.Name);

      zipWriter1.WriteItemLocalHeader(zipItemLocalHeader1);

      byte[] buffer = new byte[1024];

      int read = 0;

      using (FileStream fs = file.OpenRead())

      {

        //Read the current item's data

        while ((read = fs.Read(buffer, 0, buffer.Length)) != 0)

        {

          //Write the current item's data to the Zip archive

          zipWriter1.WriteItemData(buffer, 0, read);

        }

      }

    }

    //Close the Zip archive

    zipWriter1.CloseZipFile();

    Console.WriteLine("Zip archive created.");

  }

}



//The ByteProgression event's handler. Demonstrates the use of

//the properties of ZipWriterByteProgressionEventArgs.

static void zipWriter1_ByteProgression(object sender, 

  ZipWriterByteProgressionEventArgs e)

{

  Console.WriteLine("Item {0}: CompressionMethod = {1},

    CompressionLevel = {2}.", e.ZipItemLocalHeader.FileName,

    e.ZipItemLocalHeader.CompressionMethod,

    e.ZipItemLocalHeader.CompressionLevel);

}
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