ZipArchive.OnExtracting Event


Occurs when a file is being extracted from current zip file.

[Visual Basic]
Public Event OnExtracting As OnExtractingEventHandler
Public Delegate Sub OnExtractingEventHandler( _
    ByVal sender As Object, _
    ByVal z As ZipFile, _
    ByVal extracted As Long, _
    ByVal total As Long, _
    ByRef cancel As Boolean _
)
[C#]
public event OnExtractingEventHandler OnExtracting;
public delegate void OnExtractingEventHandler( 
     object sender, 
     ZipFile z,
     long extracted,
     long total,
     ref bool cancel 
);
[C++]
public: __event OnExtractingEventHandler* OnExtracting;
public __gc __delegate void OnExtractingEventHandler( 
     Object* sender, 
     ZipFile* z,
     __int64 extracted,
     __int64 total,
     bool __gc *cancel 
);
[JScript] In JScript, you can handle the events defined by a class. However, you cannot define your own.

Event Data

sender
The source (ZipArchive instance) of the event.
z
The (ZipFile instance) being extracted.
extracted
The file size of the file extracted in byte.
total
The file size in byte.
cancel
Gets or sets a value indicating whether the task should be canceled.

Remarks

If cancel parameter is set to true in the event, the client terminates the task immediately and a UserTerminatedException exception will be thrown.

Example

[Visual Basic, C#, C++]To get the complete samples of EACompression, please refer to Samples section.

[Visual Basic]
Imports EACompression
Imports System.IO

Module Module1
    Sub Main()
        Try
            Dim oZip As New ZipArchive("TryIt")
            AddHandler oZip.OnExtracting, AddressOf OnExtracting
            
            oZip.Load("c:\test.zip")
            Dim password As String = ""
            oZip.ExtractAll( "c:\unzipped", password )
            
        Catch ep As Exception
            Console.Write(ep.Message)
        End Try
    End Sub

    Sub OnExtracting( _
    ByVal sender As Object, _
    ByVal z As ZipFile, _
    ByVal extracted As Long, _
    ByVal total As Long, _
    ByRef cancel As Boolean _
)
        If extracted = 0 Then
            Console.WriteLine("{0}", z.FullName)
        Else
            Console.WriteLine("{0}/{1}", extracted, total)
        End If
    End Sub
End Module

[C#]
using System;
using EACompression;
using System.IO;

namespace test
{
    class Class1
    {
        public static void OnExtracting( 
            object sender, 
            ZipFile z, 
            long extracted, 
            long total, 
            ref bool cancel )
        {
            if( extracted == 0 )
            {
                Console.WriteLine( "{0}", z.FullName );
            }
            else
            {
                Console.WriteLine( "{0}/{1}", extracted, total );
            }
        }
        
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                ZipArchive oZip = new ZipArchive( "TryIt" );
                oZip.OnExtracting += new ZipArchive.OnExtractingEventHandler( OnExtracting );
                oZip.Load( "c:\\test.zip" );
                
                string password = "";
                oZip.ExtractAll( "c:\\unzipped", password );
            
            }
            catch( Exception ep )
            {
                Console.Write( ep.Message );
            }       
        }   
    }
}

[C++]
using namespace System;
using namespace System::IO;
using namespace EACompression;

public __gc class ZipArchiveEventHandler
{
public:
    static void OnExtracting( 
        Object* sender, 
        ZipFile* z,
        __int64 extracted,
        __int64 total,
        bool __gc *cancel 
    )
    {
        if( extracted == 0 )
            Console::WriteLine( S"{0}", z->FullName );
        else
            Console::WriteLine( S"{0}/{1}", __box(extracted), __box(total));
    }
};

int _tmain()
{
    try
    {
       ZipArchive *oZip = new ZipArchive( S"TryIt" );
       oZip->OnExtracting += new ZipArchive::OnExtractingEventHandler( NULL, &ZipArchiveEventHandler::OnExtracting );
       oZip->Load( S"c:\\test.zip" );
    
        String *password = S"";
        oZip->ExtractAll( S"c:\\uuzipped", password );
    }
    catch( Exception *ep )
    {
        Console::Write( ep->Message );
    }
    return 0;
}