4D v12.4

COMPRESS BLOB

Home

 
4D v12.4
COMPRESS BLOB

 

COMPRESS BLOB 


 

COMPRESS BLOB ( blob {; compression} ) 
Parameter Type   Description
blob  BLOB in BLOB to compress
compression  Longint in If not omitted: 1, compress as compact as possible 2, compress as fast as possible

The COMPRESS BLOB command compresses the BLOB blob using the internal 4D compression algorithm. This command only compresses BLOB whose size is over 255 bytes.

The optional compression parameter allows to set the way the BLOB will be compressed:

  • If you pass 1, the BLOB is compressed as much as possible, at the expanse of the speed of compression and decompression operations.
  • If you pass 2, the BLOB is compressed as fast as possible (and will be decompressed as fast as possible), at the expense of the compression ratio (the compressed BLOB will be bigger).
  • If you pass another value or if you omit the parameter, the BLOB is compressed as much as possible, using the compression mode 1.

4D provides the following predefined constants:

Constant Type Value Comment
Compact compression mode Longint 1 Compressed as much as possible (at the expense of the speed of compression and decompression operations). Default method.
Fast compression mode Longint 2 Compressed as fast as possible (and will be decompressed as fast as possible), at the expense of the compression ratio (the compressed BLOB will be bigger).

After the call, the OK variable is set to 1 if the BLOB has been successfully compressed. If the compression could not be performed, the OK variable is set to 0. If the compression could not be performed because of a lack of memory or because the actual size of the blob is less than 255 bytes, no error is generated and the method resumes its execution.
In any other cases (i.e. the BLOB is damaged), the error -10600 is generated. This error can be trapped using the ON ERR CALL command.

After a BLOB has been compressed, you can expand it using the EXPAND BLOB command.

To detect if a BLOB has been compressed, use the BLOB PROPERTIES command.

WARNING: A compressed BLOB is still a BLOB, so there is nothing to stop you from modifying its contents. However, if you do so, the EXPAND BLOB command will not be able to decompress the BLOB properly.

This example tests if the BLOB vxMyBlob is compressed, and, if it is not, compresses it:

 BLOB PROPERTIES(vxMyBlob;$vlCompressed;$vlExpandedSize;$vlCurrentSize)
 If($vlCompressed=Is not compressed)
    COMPRESS BLOB(vxMyBlob)
 End if

Note however, that if you apply COMPRESS BLOB to an already compressed BLOB, the command detects it and does nothing.

This example allows you to select a document and then compress it:

 $vhDocRef :=Open document("")
 If(OK=1)
    CLOSE DOCUMENT($vhDocRef)
    DOCUMENT TO BLOB(Document;vxBlob)
    If(OK=1)
       COMPRESS BLOB(vxBlob)
       If(OK=1)
          BLOB TO DOCUMENT(Document;vxBlob)
       End if
    End if
 End if

The OK variable is set to 1 if the BLOB has been successfully compressed; otherwise, it is set to 0.

 
PROPERTIES 

Product: 4D
Theme: BLOB
Number: 534

The OK variable is changed by the commandThis command modifies the Error system variable

 
HISTORY 

Modified: 4D v6.5.3

 
SEE ALSO 

BLOB PROPERTIES
EXPAND BLOB

 
TAGS 

Compression, blob compression***