Difference between revisions of "bzip2lib"

From Lazarus wiki
Jump to navigationJump to search
(Stream classes for bzip2 compression and decompression)
Line 15: Line 15:
  
 
The download contains the source unit file and a demo program which compresses and then again decompresses a text file given as a command line parameter.
 
The download contains the source unit file and a demo program which compresses and then again decompresses a text file given as a command line parameter.
 
  
 
=== Author ===
 
=== Author ===
 
 
Juha Manninen <juha dot manninen (at) phnet dot fi>
 
Juha Manninen <juha dot manninen (at) phnet dot fi>
  
Line 25: Line 23:
 
=== License ===
 
=== License ===
 
This code is licensed under the same terms as Jcl library.
 
This code is licensed under the same terms as Jcl library.
 
  
 
=== Download ===
 
=== Download ===
 
The latest stable release can be found on ''link to the lazarus-ccr sf download location''.
 
The latest stable release can be found on ''link to the lazarus-ccr sf download location''.
 
  
 
=== Change Log ===
 
=== Change Log ===
 
* Version 1.0,  Date: 2009.11.06
 
* Version 1.0,  Date: 2009.11.06
 
  
 
=== Dependencies / System Requirements ===
 
=== Dependencies / System Requirements ===
 
 
The code uses external bzip2 libraries for its job:
 
The code uses external bzip2 libraries for its job:
 
   'bzip2.dll' in Windows
 
   'bzip2.dll' in Windows
Line 46: Line 40:
  
 
=== Usage ===
 
=== Usage ===
 
 
Just include unit bzip2lib in the "uses" section.
 
Just include unit bzip2lib in the "uses" section.
 
External bzip2 library must be installed in your machine (see *Dependencies*).
 
External bzip2 library must be installed in your machine (see *Dependencies*).
 
Use TBzip2CompressStream and TBzip2DecompressStream just like any stream,
 
Use TBzip2CompressStream and TBzip2DecompressStream just like any stream,
 
connecting them to file stream or memory stream if needed.
 
connecting them to file stream or memory stream if needed.
 
  
 
=== Example code for bzip2lib ===
 
=== Example code for bzip2lib ===
 
 
* Compressing a string to a file. "S" is the string to compress.
 
* Compressing a string to a file. "S" is the string to compress.
  

Revision as of 15:25, 6 November 2009

About

bzip2lib provides stream classes for bzip2 compression and decompression.

Unit bzip2lib contains 2 stream classes for BZIP2 compression and decompression:

  • TBzip2CompressStream for compressing (packing) data to bzip2 format.
  • TBzip2DecompressStream for decompressing (unpacking) data back to its original form.

Unit bzip2lib is collected and edited from 2 unit files in Jcl package:

  • JclCompression
  • bzip2

The purpose was to make it compile and work with FPC (Free Pascal Compiler). In the process lots of code with conditional compilation directives were removed and also many unit dependencies were removed.

The download contains the source unit file and a demo program which compresses and then again decompresses a text file given as a command line parameter.

Author

Juha Manninen <juha dot manninen (at) phnet dot fi>

+ the original authors from Jcl code.

License

This code is licensed under the same terms as Jcl library.

Download

The latest stable release can be found on link to the lazarus-ccr sf download location.

Change Log

  • Version 1.0, Date: 2009.11.06

Dependencies / System Requirements

The code uses external bzip2 libraries for its job:

 'bzip2.dll' in Windows
 'libbz2.so.1' in Linux

Status: Stable

Issues: The author has tested the code only under Linux. There is works well.

Usage

Just include unit bzip2lib in the "uses" section. External bzip2 library must be installed in your machine (see *Dependencies*). Use TBzip2CompressStream and TBzip2DecompressStream just like any stream, connecting them to file stream or memory stream if needed.

Example code for bzip2lib

  • Compressing a string to a file. "S" is the string to compress.

<Delphi>

 OutFileStream := TFileStream.Create(CompressedFileName, fmCreate);
 try
   CompressStream := TBzip2CompressStream.Create(OutFileStream);
   try
     CompressStream.Write(Pointer(S)^, Length(S));
   finally
     CompressStream.Free;
   end;
 finally
   OutFileStream.Free;
 end;

</Delphi>

  • Decompressing from a file to a TStringList. TStringList.LoadFromStream can be used here.

<Delphi>

 InFileStream := TFileStream.Create(CompressedFileName, fmOpenRead);
 DecompressStream := TBzip2DecompressStream.Create(InFileStream);
 try
   SL.Clear;
   SL.LoadFromStream(DecompressStream);
   SL.SaveToFile(OutFileName);
 finally
   InFileStream.Free;
 end;

</Delphi>