Sign in Join
Wiki copytemporary

bzip2lib

About

bzip2lib provides stream classes for bzip2 compression and decompression. It uses external bzip2 libraries.

Unit bzip2lib contains 2 streams:

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

The purpose was to make it compile and work with FPC (Free Pascal Compiler). In the process lots of code with conditional compilation directives was 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 of Jcl code.

License

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

Download

The latest stable release can be found on http://sourceforge.net/projects/lazarus-ccr/files/bzip2lib/bzip2lib-1.tar.gz/download.

Change Log

Dependencies / System Requirements

The code uses external bzip2 libraries for its job:

Status: Stable

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

Usage

Just include unit bzip2lib in the "uses" section. Set path for it in project settings if needed. The 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.

Note: there is a bzip2 component supplied with FPC: packages/bzip2. It is a pure Pascal solution (doesn't need external libraries) but it can only decompress. If you also need compression then bzip2lib is for you.

Example code for bzip2lib

pascal
OutFileStream := TFileStream.Create(CompressedFileName, fmCreate);
CompressStream := TBzip2CompressStream.Create(OutFileStream);
try
  CompressStream.Write(Pointer(S)^, Length(S));
finally
  CompressStream.Free;
  OutFileStream.Free;
end;
pascal
SL := TStringList.Create;
InFileStream := TFileStream.Create(CompressedFileName, fmOpenRead);
DecompressStream := TBzip2DecompressStream.Create(InFileStream);
try
  SL.LoadFromStream(DecompressStream);
  SL.SaveToFile(OutFileName);
finally
  DecompressStream.Free;
  InFileStream.Free;
  SL.Free;
end;

From the Free Pascal wiki, page "bzip2lib", as it stood on 2020-07-29 after a change by Rvasin, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.