s c h e m a t i c s : c o o k b o o k

/ Cookbook.GunzippingProgressivelyWithAPipe

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Decompressing a gzipped file progressively using a pipe

Problem

We have a file that has been gzipped, and we would like to gunzip it. However, the function gunzip-through-ports in the inflate mzlib library takes in an input-port, and immediately writes the results into an output-port. It would be nice if we could instead wrap the input-port with an on-the-fly decompressor, so that clients only had to worry about working with input-ports.

Solution

The idea is to use a pipe to reconnect the output to an input port that the client can use:

(module wrap-gunzip mzscheme
  (require (lib "inflate.ss"))

  ;; wrap-gunzip: input-port -> input-port
  ;; Wraps an uncompressor around the input stream.
  (define (wrap-gunzip original-ip)
    (define-values (ip op) (make-pipe 32768))
    (thread (lambda () (gunzip-through-ports original-ip op)))
    ip))

Discussion

We restrict the size of the pipe so that we don't suck the whole file into memory.


Comments about this recipe

Contributors

-- DannyYoo - 21 May 2006

CookbookForm
TopicType: Recipe
ParentTopic: FileChapter
TopicOrder: 999

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest