Xceed Zip Compression Library Documentation
Compression entirely in memory
Getting started quickly > Compression entirely in memory

Compression entirely in memory

To compress entirely in memory, from one memory buffer to another, use the Xceed Compression control's Compress method. Keep in mind that this is a different control than the Xceed Zip control. To uncompress data that has been compressed this way, use the Xceed Compression control's Uncompress method. The output of the Compress method is always a byte array variant.

Below you will find VB and Delphi examples.

Visual Basic Copy Code

' Don't forget to put an Xceed Compression control on a form
Dim CompressedData As Variant
Dim OriginalData As Variant 

Call XceedCompression1.License( "your license key" )

XceedCompression1.Compress "This is some text to compress", CompressedData, True
XceedCompression1.Uncompress CompressedData, OriginalData, True

Debug.Print OriginalData

In the example above, the return values of the Compress and Uncompress methods were ignored. Also, an encryption password was not used. However, you could add error checking and passwords, as in the following example:

Visual Basic Copy Code

Dim CompressedData As Variant
Dim OriginalData As Variant
Dim ResultCode As xcdError 

Call XceedCompression1.License( "your license key" )

XceedCompression1.EncryptionPassword = "the password"
ResultCode = XceedCompression1.Compress("This is some text to compress", CompressedData, True) 

If ResultCode <> xceSuccess Then 
   MsgBox "Error #" + Str(ResultCode) + " while compressing the data." 
End If 

ResultCode = XceedCompression1.Uncompress(CompressedData, OriginalData, True) 

If ResultCode <> xceSuccess Then 
   MsgBox "Error #" + Str(ResultCode) +" while decompressing the data." 
EndIf 

Debug.Print OriginalData

Delphi Copy Code

var

   xErr : xcdCompressionError; 
   vaCompressedData : OleVariant; 
   vaOrigData : OleVariant; 
   vaUncompressedData : OleVariant;  

   begin
      vaOrigData := 'This is some text to compress compress compress';  

      XceedCompression1.License( 'your license key' );
      xErr := XceedCompression1.Compress( vaOrigData, vaCompressedData, true );  

      ShowMessage( 'Compress result: ' + XceedCompression1.GetErrorDescription( xErr ) );  

      if ( xErr = xceSuccess ) then 
      begin 
         xErr := XceedCompression1.Uncompress( vaCompressedData, vaUncompressedData, true ); 
        ShowMessage( 'Uncompress result: ' + XceedCompression1.GetErrorDescription( xErr ) ); 
      end; 
   end;