Search code examples
delphizippascallazarus

Extract zip file to TStream using zlibar in Lazarus


I'm trying to extract a zip file from a TMemoryStream to another TMemoryStream using zlibar in Lazarus. From what I can tell, my code follows the examples found here. I am using a simple zip archive with one text file in it. The zip archive was created using PowerArchiver, nothing special. Here is my code:

uses
  zlibar;
var
  z, Dest: TMemoryStream;
  unZip: TZLibReadArchive;     
begin
  z := TMemoryStream.Create;
  z.LoadFromFile('kov.zip');
  unZip := TZLibReadArchive.Create(z);
  UnZip.ExtractFileToStream(0, Dest);

I am getting this error: "ZLibError(2) corrupt file or not a correct file type."
See zlibar.pas here: https://dl.dropbox.com/u/8899944/files/zlibar.pas
Any ideas why I am getting this error? Thanks.


Solution

  • The Zlibar library does not read zip files. It reads and writes a custom archive format. You can tell because the table-of-contents format described in zlibar.pas is completely different from the one used in zip files.

    The FreePascalArchivePackage link looks like it might someday provide what you want, although the page last had significant changes in 2007.

    There's also the ZipFile package, which appears to come with Lazarus.