SICStus Prolog zlib Module
Nov 27, 2009
Tags: dev, prolog
For my own purposes I wrote a simple zlib module for SICStus 3. But since it may be useful to others, I have made it available. The module provides three predicates for compressing and uncompressing byte lists:
zlib_compress(+UncompressedByteList,-CompressedByteList) zlib_compress(+UncompressedByteList,+Level,-CompressedByteList) zlib_uncompress(+CompressedBytesList,+UncompressedLength,-UncompressedByteList)
CompressedByteList just contain the compressed data without any other information. Applications should keep the length of the uncompressed byte list to be able to perform successful decompression.
It is often useful to directly compress very large terms. Such functionality is provided through separate term compression predicates:
zlib_compress_term(+Term,-CompressedByteList,-UncompressedLength) zlib_compress_term(+Term,+Level,-CompressedByteList,-UncompressedLength) zlib_uncompress_term(+CompressedByteList,+UncompressedLength,-Term)
The term compression predicates separate goals blocked on term variables from the term, and the term and blocked goals are then written to a buffer using the fastrw module for fast reconstruction. The fastrw representation is then compressed.