zlib ==== This module uses :doc:`zlib-binding` to create a more idiomatic Open Dylan API to zlib. .. current-library:: zlib .. current-module:: zlib Conditions ---------- .. class:: Superclass of all error types signaled by the zlib library. :superclasses: :drm:`` :seealso: - :class:`` - :class:`` - :class:`` - :class:`` - :class:`` - :class:`` - :class:`` - :class:`` .. class:: :superclasses: :class:`` .. class:: :superclasses: :class:`` :seealso: See :const:`$z-stream-error`. .. class:: :superclasses: :class:`` :seealso: See :const:`$z-data-error`. .. class:: :superclasses: :class:`` :seealso: See :const:`$z-mem-error`. .. class:: :superclasses: :class:`` :seealso: See :const:`$z-buf-error`. .. class:: :superclasses: :class:`` :seealso: See :const:`$z-version-error`. .. class:: There was an unexpected error compressing or decompressing. :superclasses: :class:`` Compression / Uncompression --------------------------- ``zlib-compress`` ^^^^^^^^^^^^^^^^^ .. function:: zlib-compress :signature: zlib-compress *string* #key *level* => (*compressed*) :parameter string: An instance of :drm:``. String to compress. :parameter #key level: An instance of :drm:``. A number between 0 and 9, from no compression to best compression. Use :const:`$z-best-speed` for best speed, :const:`$z-best-compression` for best compression. :const:`$z-no-compression` gives no compression at all. If absent, it uses :const:`$z-default-compression` as a compromise between speed and compression. :seealso: :ref:`Compression levels` :example: The following code compress a string with a :const:`$z-default-compression` level. .. code-block:: dylan let phrase = "A horse, a horse, my kingdom for a horse"; let compressed = zlib-compress(phrase); format-out("Phrase size: %d Compressed size: %d\n", phrase.size, compressed.size); Now we compress the string using the maximum compression level (:const:`$z-best-compression`). .. code-block:: dylan let phrase = "Brevity is the soul of wit"; let compressed = zlib-compress(phrase, level: $z-best-compression); ``zlib-uncompress`` ^^^^^^^^^^^^^^^^^^^ .. function:: zlib-uncompress Uncompress a previously compressed string. :signature: zlib-uncompress *compressed* *length* => (*string*) :parameter compressed: An instance of :drm:``. A compressed string. :parameter length: An instance of :drm:``. Length of the uncompressed string. The size of the uncompressed data must have been saved previously by the compressor. :value string: An instance of :drm:``. Uncompressed string. :example: .. code:: dylan let phrase = "A horse, a horse, my kingdom for a horse"; let compressed = zlib-compress(phrase); let uncompressed = zlib-uncompress(compressed, phrase.size); format-out("Phrase: %s Uncompressed: %s\n", phrase, uncompressed);