#lang scribble/doc @(require scribble/manual planet/scribble "main.rkt") @(require (for-label racket "main.rkt" (this-package-in main))) @title{gzip} @author{Jens Axel Søgaard} @section{History} @verbatim{ 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 } @section{Introduction} This library provides bindings to the general purpose compression library zlib written by Jean-loup Gailly and Mark Adler. @link["http://www.zlib.net/manual.html"]{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. @section{Installation} On Mac and Unix download zlib, if you get an error message from the above. @section{Functions} @defmodule/this-package[main]{ @defproc[(open-input-gz-file [path path?]) port?]{ The function open-input-gz-file opens an existing gz-file and returns an input port. Example: @racketblock[ > (define in (open-input-gz-file (string->path "fooo.gz"))) > (read-bytes 9 in) #"123344445" > (close-input-port in) ] } @defproc[(open-output-gz-file [path path?] [#:replace replace boolean? #f]) port?]{ 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: @racketblock[ > (define out (open-output-gz-file "fooo.gz" #:replace #t)) > (write-bytes #"123" out) > (write-bytes #"344445" out) > (close-output-port out) ]} @defproc[(read-gz-file [path path?]) bytes?]{ 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. } @defproc[(compress-bytes [bytes bytes?]) bytes?]{ Compresses the bytes in the input and returns a byte string containing the compressed result. Example: @racketblock[ > (compress-bytes #"1234") #"x\2343426\1\0\1\370\0\313" ]} @defproc[(uncompress-bytes [compressed bytes?] [expanded-length exact-nonnegative-integer?]) bytes]{ 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: @racketblock[ > (uncompress-bytes (compress-bytes #"1234") 4) #"1234" ]} } @section{Keywords} Keywords: _compression_ _decompression_ _gzip_ _gz_ _zlib_