Re: [bds 2006] Decompress .gz files with zlib unit?



Wolfgang Ehrhardt wrote:
> gz files (normally) are gzip compressed files. The gzip stream format
> is slightly different from plain zlib streams, although gzip I/O can
> be implemented with zlib, as it is shown with the gzio.c file in the
> zlib distribution. zlib versions newer that 1.1.4 have enhanced gzip
> support.
>
> All versions of Delphi (that I know of) do have a "own" (sub-optimal)
> interface to zlib. Delphi uses the C compiled obj files (and gzio.obj
> is missing),

Thanks Wolfgang:

I have been trying to use a zlib 1.2.3 unit download from
http://www.base2ti.com/cgi-bin/download.exe?folder=delphi+zlib&file=delphi+zlib+1.2.3

The ZLibEx.pas has two TZDecompressionStream constructors
-----------
constructor TZDecompressionStream.Create(source: TStream);
begin
inherited Create(source);

FZStream.next_in := FBuffer;
FZStream.avail_in := 0;

ZDecompressCheck(InflateInit(FZStream));
end;

constructor TZDecompressionStream.Create(source: TStream;
windowBits: Integer);
begin
inherited Create(source);

FZStream.next_in := FBuffer;
FZStream.avail_in := 0;

ZDecompressCheck(InflateInit2(FZStream,windowBits));
end;
-----------

>From what I understand (zlib.h), *Init is for zlib wrapped and the *Init2 is
for gzip wrapped. That being I would presume to want to do something like
[ note the ,12 -- the second form of the constructor that uses
InflateInit2 ]
------------------------
bufferSize := 1000;
GetMem (pBuffer, bufferSize);

z := TZDecompressionStream.Create(TFileStream.Create(gzfile,
fmOpenRead),12);

bytesRead := z.Read(pBuffer^, bufferSize);

z.Free();

WriteLn (bytesRead, ' bytes read.');
WriteLn (String(pBuffer^));

FreeMem(pBuffer, bufferSize);

WriteLn('Done.');
ReadLn;
------------------------

Unfortunately, this raises a Data Error exception.


--
Richard A. DeVenezia
http://www.devenezia.com/


.



Relevant Pages

  • Re: zlib with gzip file
    ... That does raw inflation, not gzip decoding. ... For background, a zlib ... different header - deflate data - different trailer. ...
    (comp.compression)
  • Re: howto create a zip programmatically
    ... >>>>It's just that i'm not aware if gzip is compatible with WinZip, ... >>>>WinZip then so will be the files created with zlib. ... >> To use the ZLIB library to create PKZIP compatible archives, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: howto create a zip programmatically
    ... "Norm Dresner" wrote in message ... >> It's just that i'm not aware if gzip is compatible with WinZip, ... >> WinZip then so will be the files created with zlib. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Low CPU standard compressor?
    ... > gun 2.2 ... > gzip 3.6 ... > "gun" is a gzip decompressor that uses the latest version of zlib and ... Please give the absolute version number of zlib that was tested. ...
    (comp.compression)
  • Re: zlib and zipfile module in Python2.4
    ... python still builds gzip ... ... which imports zlib. ... gzip is a Python module, ... importing gzip gives you an ImportError exception. ...
    (comp.lang.python)