1 History
2 Introduction
3 Installation
4 Functions
open-input-gz-file
open-output-gz-file
read-gz-file
compress-bytes
uncompress-bytes
5 Keywords

gzip

Jens Axel Søgaard

1 History

2011-may-17  Fixed "version 400" problem

             Translated doc.txt to doc.scrbl (JBC)

2009-feb-6   Port to 4xx.

             Added support for mac os x.

 

2007-feb-17  First release.

               - open-input-gz-file

               - open-output-gz-file

               - read-gz-file

               - compress-bytes

               - uncompress-bytes

2 Introduction

This library provides bindings to the general purpose compression library zlib written by Jean-loup Gailly and Mark Adler.

http://www.zlib.net/manual.html

For convenience for Windows users, the dll-file zlib1.dll is included with this PLaneT package.

Note, that gzip-files are already supported in file/gzip and file/gunzip. However, as of 2011-04, those libraries don’t support the ADLER32 checksum, and therefore cannot be used to write zlib-encoded streams. This library therefore provides the easiest way to compress data terminated by an ADLER32 checksum.

3 Installation

On Mac and Unix download zlib, if you get an error message from the above.

4 Functions

 (require (planet soegaard/gzip:2:2))

(open-input-gz-file path)  port?
  path : path?
The function open-input-gz-file opens an existing gz-file and returns an input port.

Example:
> (define in (open-input-gz-file (string->path "fooo.gz")))
> (read-bytes 9 in)
#"123344445"
> (close-input-port in)

(open-output-gz-file path    
  [#:replace replace])  port?
  path : path?
  replace : boolean? = #f
The function open-output-gz-file opens a file and returns an output port. Output written to the output port is compressed using the gzip algorithm. Remember to close the port, before reading from the file.

If the file exists the exception exn:file-system:exists will be raised, unless the option ’replace is present, in that case the existing file will be replaced.
Example:
> (define out (open-output-gz-file "fooo.gz" #:replace #t))
> (write-bytes #"123" out)
> (write-bytes #"344445" out)
> (close-output-port out)

(read-gz-file path)  bytes?
  path : path?
Uncompresses the entire file given by path, and returns a byte string as the result.

Faster than using open-input-gz-file and reading everything into a byte string.

(compress-bytes bytes)  bytes?
  bytes : bytes?
Compresses the bytes in the input and returns a byte string containing the compressed result.

Example:
> (compress-bytes #"1234")
#"x\2343426\1\0\1\370\0\313"

(uncompress-bytes compressed    
  expanded-length)  bytes
  compressed : bytes?
  expanded-length : exact-nonnegative-integer?
A call (uncompress-bytes compressed-bytes uncompressed-size) will uncompress the bytes in compressed-bytes and return the uncompressed result as a byte string. The size of the uncompressed data must be given as the second argument.

Example:
> (uncompress-bytes
   (compress-bytes #"1234")
   4)
#"1234"

5 Keywords

Keywords: _compression_ _decompression_ _gzip_ _gz_ _zlib_