Recent

Author Topic: LZ4 decompressor in pure Pascal  (Read 460 times)

Tomxe

  • New Member
  • *
  • Posts: 46
LZ4 decompressor in pure Pascal
« on: March 22, 2025, 10:10:08 am »
Pure pascal decoder for LZ4 files/data
https://github.com/Xelitan/LZ4-decompressor-in-pure-Pascal/

Usage example:
Code: Pascal  [Select][+][-]
  1. var F,P: TFileStream;
  2. begin
  3.   F := TFileStream.Create('test.lz4', fmOpenRead);
  4.   P := TFileStream.Create('test.txt', fmCreate);
  5.  
  6.   LZ4DecodeStream(F, P);
  7.  
  8.   p.Free;
  9.   F.Free;
  10. end;

Also:
Code: Pascal  [Select][+][-]
  1. var InData, OutData: TBytes;
  2.     F: TFileStream;
  3.     Str: String;
  4. begin
  5.   F := TFileStream.Create('test.lz4', fmOpenRead);
  6.   SetLength(InData, F.Size);
  7.   F.Read(InData[0], F.Size);
  8.   F.Free;
  9.  
  10.   OutData := LZ4Decode(InData);
  11.   SetLength(Str, Length(OutData));
  12.   Move(OutData[0], Str[1], Length(Str));
  13.  
  14.   Memo1.Lines.Add(Str);
  15. end;

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12162
  • FPC developer.
Re: LZ4 decompressor in pure Pascal
« Reply #1 on: March 22, 2025, 11:47:14 am »
A tip, move the exception.create's on error to an own procedures e.g. something

Code: Pascal  [Select][+][-]
  1. procedure lz4errror(const Message:string);
  2. begin
  3.   raise Exception.Create(message);
  4. end;
  5.  

it saves the need for exception frames, at least on targets that don't have tabled based exceptions.

Tomxe

  • New Member
  • *
  • Posts: 46
Re: LZ4 decompressor in pure Pascal
« Reply #2 on: March 22, 2025, 02:17:35 pm »
Okay, but which targets don't have tabled based exceptions?

ALLIGATOR

  • Full Member
  • ***
  • Posts: 148
Re: LZ4 decompressor in pure Pascal
« Reply #3 on: March 22, 2025, 02:40:05 pm »
🆒

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12162
  • FPC developer.
Re: LZ4 decompressor in pure Pascal
« Reply #4 on: March 22, 2025, 02:56:48 pm »
Okay, but which targets don't have tabled based exceptions?

I'm not sure about open source *nix.  Just compile and inspect the assembler if you want to know.

Afaik OS X and Windows do implement them.

 

TinyPortal © 2005-2018