Difference between revisions of "Zlibar"

From Free Pascal wiki
Jump to navigationJump to search
Line 19: Line 19:
 
* Files in the archive are extractable by an index number and are extracted to a TStream
 
* Files in the archive are extractable by an index number and are extracted to a TStream
  
The download contains a demo program, and the unit. There is no package file included.
+
The download contains a demo program, and the unit. Also a package file.
  
 
Although not tested, it should work on any platform.
 
Although not tested, it should work on any platform.

Revision as of 21:25, 2 September 2005

About

zlibar is a unit that contains components to create a single compressed file archive that contains many files. It uses paszlib that is included with FreePascal so there are no external library requirements

The two main components are :

  • TZlibWriteArchive - Used to create an archive
  • TZlibReadArchive - Used to read the archive and extract it's files

Features of TZlibWriteArchive :

  • Create the Archive file in a stream, allowing you to save it to a file or do something else creative with it
  • Each file in the archive is stored with a MD5 checksum
  • Each file can be stored with a relative path
  • Contains progress callbacks to inform the program of the current file and all files progress

Features of TZlibReadArchive :

  • Loads the archive from a TStream.
  • Contains a progress callback to inform the program of the extraction progress
  • Files in the archive are extractable by an index number and are extracted to a TStream

The download contains a demo program, and the unit. Also a package file.

Although not tested, it should work on any platform.

Author

Andrew Haines

License

zlibar.pas is distributed with the same modified LGPL as the LCL, so it is possible to use it in proprietary programs.


Download

The latest stable release can be found on the Lazarus CCR Files page.

Dependencies / System Requirements

  • FreePascal
  • Demo Program requires Lazarus

Issues: Tested on Linux. Needs testing on Windows.

Usage

Add the unit "zlibar" to your uses section.

TZLibWriteArchive

Example:

 var
 Zar: TZlibWriteArchive;
 Stream: TMemoryStream;
 X: Integer;
 begin    
   Stream := TMemoryStream.Create;
   Zar := TZlibWriteArchive.Create;    
   Zar.OutStream := Stream;
 
   Zar.InputFiles.Add('/path/to/MyFileName1');
   Zar.InputFiles.Add('/path/to/MyFileName2');
 
   Zar.CreateArchive;
 
   Stream.SaveToFile('MySavedFileName');
   Zar.Free;
   Stream.Free;
 end;

TZlibReadArchive

Example:

 var
 ArchStream: TMemoryStream;
 FileStream: TMemoryStream;
 ZReadArc: TZlibReadArchive;
 X: Integer;
 DestPath: String;
 begin
   ArchStream := TMemoryStream.Create;
   FileStream := TmemoryStream.Create;
   
   ArchStream.LoadFromFile('ArchiveFileName');
   ZReadArc:= TZlibReadArchive.Create(ArchStream);
   DestPath := '/Some/Path';
   for X := 0 to ZReadArc.Count -1 do begin    
     ZReadArc.ExtractFileToStream(X, FileStream);
     FileStream.SaveToFile(DestPath+ZReadStream.FilesInArchive[X].FilePath+'/'+ZReadStream.FilesInArchive[X].FIleName);
     FileStream.Position := 0;
     FileStream.Size := 0;
   end;
   ZReadArc.Free;
   ArchStream.Free;
   FileStream.Free;  
 end;