Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

LZ4-Compression-Decompression-for-Delphi-Lazarus

LZ4 Compression and Decompression for Delphi, Lazarus, Free Pascal

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

LZ4-Compression-Decompression-for-Delphi-Lazarus

LZ4 Compression and Decompression for Delphi, Lazarus, Free Pascal

Usage examples

pascal
var F,S: TFileStream;
    Size: Integer;
begin
  LZ4_COMPRESSION := 1; //small files but slow
  LZ4_COMPRESSION := 50; //bigger files, faster

  F := TFileStream.Create('input.txt', fmOpenRead);
  S := TFileStream.Create('output.lz4', fmCreate);
  LZ4(F, S);
  Size := F.Size;
  F.Free;
  S.Free;

  F := TFileStream.Create('output.lz4', fmOpenRead);
  S := TFileStream.Create('output.txt', fmCreate);
  UnLZ4(F, S, Size);
  F.Free;
  S.Free;
end;

This unit uses LZ4 library:

LibLZ4.DLL is licensed under a BSD 2-Clause license. https://github.com/lz4/lz4

Concatenation

Currently this unit compresses data without buffering. So when you compress a file- a whole file is read into RAM, compressed and then saved to disk. If you want to compress huge files you should divide them into chunks, compress each chunk and then glue chunks together. Concatenation of LZ4 files is a valid LZ4 file.

Linux (Debian, Ubuntu, Mint)

  1. apt install apt-file liblz4-dev
  2. apt-file search liblz4.so It will list you how your liblz4.so files are named exactly and where they are
  3. Open LZ4Lib.pas and edit "const LZ4_LIB"
  4. Change the value of that const. Enter filename (excluding path) found in step 2
  5. Compile and run