Optimizing speed by using the transaction system
UltimateZip introduces the Transaction System which helps speed up performing multiple operations on files and folders. You can use the BeginUpdate, CancelUpdate, EndUpdate methods and InUpdate property of the Zip class to optimize speed of executing the archive updating operations.
In the setup package, we have a sample project named Transaction that demonstrates how to use Ultimate Zip library to speed up the file compression process.
The following example shows how to use the BeginUpdate method to initiate the transaction system, EndUpdate to commit changes and CancelUpdate to rollback changes when an error occurs. Before using the class, please remember adding references to the required assemblies as well as using directive for namespace Atp.Compression.
After adding the using directive, you can create a new instance of the Zip class, call the BeginUpdate method, add files to the archive, and then end the transaction with the EndUpdate method.
Using Transaction System in Ultimate Zip
| C# | |
|---|---|
|
static class TransactionSystem
{ [STAThread] static void Main() { // Open an existing file. Zip zip = new Zip("c:\\test.zip"); // Begin transaction. zip.BeginUpdate(); try { // Add all .txt files zip.AddFiles("c:\\test", "", "*.txt"); } catch (Exception) { // Cancel the transaction if an error occurs. zip.CancelUpdate(); } // Close the zip file. zip.EndUpdate(); zip.Close(); } } |
|
| VB.NET | |
|---|---|
|
Module TransactionSystem
Sub Main() ' Open an existing file. Dim zip As New Zip("c:\test.zip") ' Begin transaction. zip.BeginUpdate() Try ' Add all .txt files zip.AddFiles("c:\test", "", "*.txt") Catch e1 As Exception ' Cancel the transaction if an error occurs. zip.CancelUpdate() End Try ' Close the zip file. zip.EndUpdate() zip.Close() End Sub End Module |
|
For more details on adding files and folders to an archive, see this topic. The topic demonstrates using the AddFiles method to compress files and folders with the Ultimate compression zip library. You can also use the CopyFrom and CopyTo methods to transfer files from/to another file system. Supports file systems are FTP, SFTP, SCP, Disk, and Virtual File Systems.