Using TIdCompressorLib to Decompress gzip file
<p>I am using Delphi 2007 with Indy 10.  I have a gzip file.  I have verified it can be decompressed with this <a href="http://online.b1.org/online" rel="nofollow">Online Decompression Tool</a>.</p>

<p>I am trying to use the <strong>TIdCompressorZlib</strong> component to decompress using Delphi.  Here is my code:</p>

<pre><code>procedure TForm2.Button9Click(Sender: TObject);
var
  lCompressor : TIdCompressorZLib;
  FileStream : TFileStream;
  memorystream: TMemoryStream;
begin
  lCompressor := TIdCompressorZLib.create(self);
  FileStream := TFileStream.Create('c:\temp\test.gz', fmOpenRead);
  filestream.position := 0;
  memorystream:= TMemoryStream.create;
  memorystream.position := 0;
  lcompressor.DecompressGZipStream(FileStream,MemoryStream);
  filestream.free;
  showmessage('done');
end;
</code></pre>

<p>I cannot get it to work.  If I pass <strong>fmOpenReadWrite</strong> in the constructor I get a <strong>zlib error (-5)</strong> when DecompressGZipStream is called.</p>

<p>If I pass <strong>fmOpenRead</strong> in the constructor I get a <strong>OS System Error Code 5 Access Denied</strong> when DecompressGZipStream is called.</p>

<p><strong>Update</strong>  David Hefferan suggested it is a file reading issue.  So I am zeroing in on that.  I am able to copy the file using this procedure:</p>

<pre><code>Procedure FileCopy( Const sourcefilename, targetfilename: String );
Var
 S, T: TFileStream;
Begin
 S := TFileStream.Create( sourcefilename, fmOpenRead );
 try
   T := TFileStream.Create( targetfilename,
                            fmOpenWrite or fmCreate );
   try
     T.CopyFrom(S, S.Size ) ;
   finally
     T.Free;
   end;
 finally
   S.Free;
 end;
 showmessage('done');
End;
</code></pre>

<p><strong>UPD</strong>  Per David Heffernan, I have verified I can Read the data.  I successfully ran the file through the following function.  It returns the proper number of characters (bytes):</p>

<pre><code>function GetTextFromFile(AFile: string; var Returnstring: string): Boolean;
var
  FileStream: TFileStream;
begin
  Result := False;
  if not FileExists(AFile) then Exit;
  FileStream := TFileStream.Create(AFile, fmOpenRead);
  try
    if FileStream.Size &lt;&gt; 0 then
    begin
      SetLength(Returnstring, FileStream.Size);
      FileStream.Read(Returnstring[1], FileStream.Size);
      Result := True;
    end;
  finally
    FileStream.Free;
  end;
end;
</code></pre>