- zlib-decompressing-input-port ip #!key window-bits bufferprocedure
These options are passed to inflateInit2.
- window-bits: The history buffer size. When decompressing a stream, the window size must not be smaller than the size originally used to compress the stream. Valid ranges are:
- buffer: A string, often heavily mutated, used for internal transfers. (make-string 4096) is the default.
For example, we can decompress the zlib data from the example above like this:
(read-string #f (zlib-decompressing-input-port (open-input-string (blob->string #${789ccb48cdc9c95728cf2fca4901001a0b045d})))) ;; => "hello world"
This will expect zlib headers. To detect gzip or zlib headers, specify higher values for window-bits:.
;; $ printf "hello world" | pigz -z | xxd -plain -c0 ;; 785ecb48cdc9c95728cf2fca4901001a0b045d (define hello.zlib (blob->string #${785ecb48cdc9c95728cf2fca4901001a0b045d})) ;; $ printf "hello world" | gzip - | xxd -plain -c0 ;; 1f8b0800000000000003cb48cdc9c95728cf2fca49010085114a0d0b000000 (define hello.gz (blob->string #${1f8b0800000000000003cb48cdc9c95728cf2fca49010085114a0d0b000000})) (read-string #f (zlib-decompressing-input-port (open-input-string hello.zlib) #:window-bits 47)) ;; => "hello world" (read-string #f (zlib-decompressing-input-port (open-input-string hello.gz) #:window-bits 47)) ;; => "hello world"