XbZ_Compress()
Previous  Top  Next

XbZ_Compress() - Compress (Deflate) a string with the Default Compression Level.

Syntax

XbZ_Compress(@cData,  
            [@nError]) --> cCompressed  

Parameters

<@cData>  
<@cData> contains a string that should be compressed (with the Deflate method). This parameter must be passed by reference, even though it will not be modified.  

<@nError>  
After XbZ_Compress() returns, the optional Parameter <@nError> will contain any kind of Compression Error that might be raised by the ZLib compress() function. This parameter is optional, but must be passed by reference if it should be updated.  
 
Possible values are the following Define Constants from the XbZLib.ch file:  
 
Define
Value
Description
XBZ_OK
0
Adding/Updating of (File) Entry was successful.
XBZ_STREAM_ERROR
-2
(ZLib Error Code) Compression Level invalid.
XBZ_MEM_ERROR
-4
(ZLib Error Code) Not enough Memory.
XBZ_BUF_ERROR
-5
(ZLib Error Code) Output Buffer too small.
 

Returns

This function returns a Deflated (compressed) version of <@cData> or possibly a string that only contains spaces, if an error occurred.  

Description

This is basically an Xbase++ Wrapper Function for the ZLib Function: compress(). It returns the compressed (deflated) <@cData> as a string, and updates <@nError> with any possible Error Return Code of the ZLib Function. It is virtually identical to the XbZ_Compress2() method, but always uses the Default Compression Level value of XBZ_DEFAULT_COMPRESSION, which cannot be changed.  

Example

LOCAL nError := XbZ_OK  
LOCAL cFile  := 'XbZLib.chm'  
LOCAL cData  := XbZ_FileRead(cFile, @nError)  
LOCAL cCompr := ''  
if nError == XbZ_OK  
   cCompr := XbZ_Compress(@cData, @nError)  
   if nError # XbZ_OK  
      QOut(cFile + ' could not be compressed!')  
      QOut('Error: ' + alltrim(str(nError)))  
   endif  
else  
   QOut(cFile + ' could not be read!')  
   QOut('Error: ' + alltrim(str(nError)) + ' - ' + ;  
                DosErrorMessage(nError))  
endif