delphi zlib faq
 date  question
2001.03.06 do you have any code examples?
2001.03.06 are the objects thread safe?
2001.03.06 can the objects be used with winzip or pkzip files?
2004.02.26 is the zlibex unit freeware?

 
 do you have any code examples?
here are some simple routines to compress and decompress a file.
procedure CompressFile(const inFile, outFile: String);
var
  zStream  : TZCompressionStream;
  inStream : TFileStream;
  outStream: TFileStream;
  size     : Cardinal;
begin
  // open the in file and get the size

  inStream := TFileStream.Create(inFile,fmOpenRead);
  size := inStream.Size;

  // create the out file and save the original (decompressed)
  // file size to make decompression easier

  outStream := TFileStream.Create(outFile,fmCreate);
  outStream.Write(size,SizeOf(Cardinal));

  // compress

  zStream := TZCompressionStream.Create(outStream);
  zStream.CopyFrom(inStream,0);

  // clean up

  zStream.Free;
  outStream.Free;
  inStream.Free;
end;

procedure DecompressFile(const inFile, outFile: String);
var
  zStream  : TZDecompressionStream;
  inStream : TFileStream;
  outStream: TFileStream;
  size     : Cardinal;
begin
  // open the in file and get the original (decompressed)
  // file size

  inStream := TFileStream.Create(inFile,fmOpenRead);
  inStream.Read(size,SizeOf(Cardinal));

  // create the out file

  outStream := TFileStream.Create(outFile,fmCreate);

  // decompress

  zStream := TZDecompressionStream.Create(inStream);
  outStream.CopyFrom(zStream,size);

  // clean up

  zStream.Free;
  outStream.Free;
  inStream.Free;
end;
 
 are the objects thread safe?
yes, if used in a thread safe manner; i.e. two or more threads working with the same TZ*Stream object simultaneously with proper sychronization handling in place.
 
 can the objects be used with winzip or pkzip files?
not directly. winzip and pkzip files contain extra information about the contents of the archive. some special processing will need to be done. after this is completed, these objects may be used to compress or decompress the contained files. for additional information about the zip file format, go to:

pkzip application note on pkware's website (http://www.pkware.com/support/appnote.html)
info-zip's website (http://www.info-zip.org)
 
 is the zlibex unit freeware?
yes, the ZLibEx.pas unit is freeware and can be used freely in personal and commercial applications. i just request two things in return:

1) give me some kind of acknowledgement in some form or fashion -- an email, a readme, an about box, a help file, etc.

2) if you make modifications or improvements, please share the changes with me so i may incorporate them for everyone's benefit.

finally, the original zlib source files (*.c, *.h, etc.) are free, but have their own license agreement. it can be found at: http://www.gzip.org/zlib/zlib_license.html

  base2 technologies last modified