I prefer single EXE programs but there is no ZStandard implementation in Pascal. So here's my solution for Windows 64 bit, a bit ugly but:
1) no DLL file to distribute
2) antivirus programs don't complain- you can check on virustotal
3) easy to update Zstandard to newest release
4) easy to adapt code for Win32, Linux, MacOS.
It just extracts the DLL to the temporary folder and uses it from there. The DLL is UPX packed to be smaller.
const BufSize = 40960000;
var InF, OutF: TFileStream;
Z: TZSTDCompressStream;
Len: Integer;
Buf: array of Byte;
Options: TZSTDCompressOptions;
c1, c2, f: Int64;
begin
ZSTDDllName := GetTempDir + 'libzstd-117788.dll';
if not FileExists(ZSTDDllName) then begin
OutF := TFileStream.Create(ZSTDDllName, fmCreate);
OutF.Write(ZStdBody, Length(ZStdBody));
OutF.Free;
end;
QueryPerformanceFrequency(f);
QueryPerformanceCounter(c1);
InF := TFileStream.Create('whatever.input', fmOpenRead);
OutF := TFileStream.Create('pack.zstd', fmCreate);
Options.Init;
//Options.CompressionLevel := 100; //max
Options.CompressionLevel := 2; //fast
Z := TZSTDCompressStream.Create(OutF, Options);
SetLength(Buf, BufSize);
while InF.Position < InF.size do begin
Len := InF.Read(Buf[0], BufSize);
Z.Write(Buf[0], Len);
//OutF.Write(Buf[0], Len);
end;
Z.Free;
InF.Free;
OutF.Free;
//DeleteFile(ZSTDDllName);
QueryPerformanceCounter(c2);
ShowMessage(Format('%f sec', [ (c2-c1)/f ]));