Recent

Author Topic: Pure Pascal ZPAQ and ZSTD  (Read 479 times)

Tomxe

  • Jr. Member
  • **
  • Posts: 63
Pure Pascal ZPAQ and ZSTD
« on: April 21, 2026, 08:39:45 am »
Here are Zpaq and Zstandard compressors in Free Pascal, no DLLs, no binaries required.

https://github.com/Xelitan/Free-Pascal-port-of-LIBZPAQ-Version-7.15

https://github.com/Xelitan/Free-Pascal-port-of-ZStandard-compressor-decompressor

License: BSD/MIT

ZSTD

Usage:

Code: Pascal  [Select][+][-]
  1. function ZStd(Uncompressed: AnsiString): AnsiString;
  2. function UnZSTD(Compressed: AnsiString): AnsiString;
  3. function CompressFile(Infilename, Outfilename: String): Integer;
  4. function DecompressFile(Infilename, Outfilename: String): Integer;

ZPAQ

Simple functions:

Code: Pascal  [Select][+][-]
  1. uses ZpaqSimple;
  2. [...]
  3. function CompressStreams(Infile, Outfile: TStream): Integer;
  4. function DecompressStreams(Infile, Outfile: TStream): Integer;
  5.  
  6. function CompressFile(Infilename, Outfilename: String): Integer;
  7. function DecompressFile(Infilename, Outfilename: String): Integer;
  8.  
  9. function Zpaq(Uncompressed: AnsiString): AnsiString;
  10. function UnZpaq(Compressed: AnsiString): AnsiString;


ZPaq, packing:
Code: Pascal  [Select][+][-]
  1. uses ZpaqClasses;
  2. [...]
  3. p := TZpaqPacker.Create('pack.zpaq');  
  4. p.SetMethod(1);
  5.  
  6. f := TFileStream.Create('input.txt', fmOpenRead);
  7. p.AddFile(f, 'hello.txt');
  8. f.Free;
  9.  
  10. p.Free;

Unpacking:
Code: Pascal  [Select][+][-]
  1. uses ZpaqClasses;
  2. [...]
  3. u := TZpaqUnpacker.Create('pack.zpaq');
  4. while u.NextEntry(name, size, date) do begin
  5.  
  6.   f := TFileStream.Create(name, fmCreate);
  7.   u.Extract(f);
  8.   f.Free;
  9.  
  10. end;
  11. u.Free;    
   

More helper functions will come.
« Last Edit: April 21, 2026, 11:47:39 am by Tomxe »

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 413
  • I use FPC [main] 💪🐯💪
Re: Pure Pascal ZPAQ and ZSTD
« Reply #1 on: April 21, 2026, 09:11:40 am »
Wow! That's awesome!
I may seem rude - please don't take it personally

Tomxe

  • Jr. Member
  • **
  • Posts: 63
Re: Pure Pascal ZPAQ and ZSTD
« Reply #2 on: April 21, 2026, 11:48:23 am »
Added more functions to make it easier to use ZPAQ.

mika

  • Full Member
  • ***
  • Posts: 137
Re: Pure Pascal ZPAQ and ZSTD
« Reply #3 on: April 30, 2026, 09:15:54 am »
TReadBridge is used in ZpaqSimple, has to be exposed in interface ZpaqClasses
Code: Pascal  [Select][+][-]
  1. var
  2.   InBridge  : TReadBridge;
  3.   OutBridge : TWriteBridge;

ZSTD does not work at all. Some sort of exception is thrown.

Maybe would be good to get rid of C operators as well (just one use case).
« Last Edit: April 30, 2026, 09:19:07 am by mika »

Tomxe

  • Jr. Member
  • **
  • Posts: 63
Re: Pure Pascal ZPAQ and ZSTD
« Reply #4 on: April 30, 2026, 10:46:42 am »
Thanks for testing.
Classes exposed in Zpaq. And ZStdSimple worked fine but had a few test writelns. They are gone now.

 

TinyPortal © 2005-2018