On Sat, Feb 14, 2004 at 11:18:52PM +0800, Autrijus Tang wrote: > On Sat, Feb 14, 2004 at 01:32:50PM +0000, Nicholas Clark wrote: > > Strictly do you need a pure perl gunzip (ie the gzopen etc part of the API)? > > Or is the inflateInit() etc part of the API all that you use? > > I need whatever parts needed by Archive::Zip.
inflateInit and inflate The "fun" is that inflate is written with an interface where you pass it a section of the input data, and it returns as much output as possible, whereas Ton's example code assumes you can just read as much input as you want *as you need it*. The zlib C source code is a state machine, operating (it seems) 1 byte at a time, and capable at any point of stalling, returning and resuming on a subsequent call. Given that quite a lot of the deflate format works bit-at-a- time I think it can actually cope stalling part way through assembling bit strings. Ton's (wonderful) gunzip code is nice and "simple" because it assumed that it can read as much input as it needs on demand, and never needs to save state. (It's not simple - I wouldn't have got this far) I'm part way through trying to turn it inside out so that it can save state and return if it runs out of input. At least Compress::Zlib's interface is slightly easier than the straightjacket C zlib works under, because Compress::Zlib always consumes all input given, expanding the output buffer as necessary. Nicholas Clark
