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



Haven't used Delphi in ages, starting back up with bds 2006.

I have a bunch of .gz files that need to be decompressed (on the fly) before
I can use the data inside them.

The files are not corrupt -- WinZip was unable decompress them.

The simple console program below raises an Application Error dialog
"The exception unknown software exception (0x0eedfade) occurred in the
application at location 0x7c59bc3f"
and writes out
Exception ECompressionError in module Project2.exe at 00010AA7.
Error.

Have I missed something?
Do I need a different decompression library ?

----------------
program Project2;

{$APPTYPE CONSOLE}

uses
SysUtils, Classes, ZLib;

type
PHugeCharArray = ^THugeCharArray;
THugeCharArray = array[0..0] of Char;

var
z: TDecompressionStream;

bufferSize: Integer;
pBuffer: PHugeCharArray;

bytesRead: Integer;

begin
bufferSize := 1000;
GetMem (pBuffer, bufferSize);

z := TDecompressionStream.Create(TFileStream.Create('c:\temp\xyz.txt.gz',
fmOpenRead));

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

z.Free();

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

FreeMem(pBuffer, bufferSize);

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

The first ten bytes of the .gz are this:
1F 8B 08 08 3A E5 D4 3A 00 03



Richard


.



Relevant Pages

  • Re: How do I inflate compressed data from an asynchronous socket?
    ... Do keep in mind that you are still using the thread pool though; you just do it implicitly in this case, ... the exception is being thrown in the middle. ... it seems to me that SharpZipLib ought to provide a mechanism for cleanly dealing with errors on the NetworkStream you pass to it. ... you've tried to decompress data in one shot without having the complete data available to decompress. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Image HttpWenResponse
    ... HttpWebRequest httpWebRequest = ... int bytesRead; // The # of bytes read. ... bytesRead = receiveStream.Read(bytes, 0, bufferSize); ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: code to retrieve binary field from Sql Server
    ... BinaryWriter bw = new BinaryWriter; ... bufferIndex, bufferSize)))> 0) ... bw.Write(binaryDataBuffer, 0, bytesRead); ...
    (microsoft.public.dotnet.languages.csharp)
  • code to retrieve binary field from Sql Server
    ... BinaryWriter bw = new BinaryWriter; ... bufferIndex, bufferSize)))> 0) ... bw.Write(binaryDataBuffer, 0, bytesRead); ...
    (microsoft.public.dotnet.languages.csharp)

Loading