atom_compress(+atom, ?atom_compressed_base64)
atom_compress(?atom, +atom_compressed_base64)

This built-in predicate can (de)compress atoms. The atom to compress is the first argument, the compressed atom is the second argument. The compressed atom is encoded with the base64 encoding algorithm to create a readable atom. If the first argument is not a variable then it is compressed, encoded and unified with the second argument. If the first argument is a variable then the second argument is decoded, decompressed and unified with the first argument.

Encoding the result with base64 encoding makes the compressed atom 33% larger, so it is best only to compress atoms that are large, for instance larger than 200 characters.

see also: atom_base64/2 atom_codes/2 atom_concat/3 atom_encrypt/3 atom_final_md5/1 atom_integers/2 atom_length/2 atom_reset_md5/0 atom_update_md5/1 char_code/2 number_chars/2 number_codes/2 number_integers/2 sub_atom/5

Examples
atom_compress('tempdoc', A). The atom 'tempdoc' is compressed and then base64 encoded,
A = 'BwAAAHjaK0nNLUjJTwYAC98C7Q=='
atom_compress(A,  'BwAAAHjaK0nNLUjJTwYAC98C7Q=='). The second atom is decoded and decompressed, the result is unified with the first argument,
A = 'tempdoc'

 

Exceptions
Both arguments are variables an instantiation_error exception is thrown
The encrypted atom is not a correct base64 encoded string an evaluation_error(decode_base64, Atom64) exception is thrown

 

 

info@trinc-prolog.com