Lazarus

Programming => General => Topic started by: DanishMale on January 23, 2020, 05:06:55 pm

Title: [SOLVED] XZ files decompress
Post by: DanishMale on January 23, 2020, 05:06:55 pm
Hi,

 I am downloading a XZ compressed file from the internet and wish to extract the file to work with the contained XML file, however, something doesn't seem to work as excepted   :)

The file is perfectly downloaded and can be extracted/decompressed by WinRAR etc...

Code: Pascal  [Select][+][-]
  1. uses .....,BZip2Lib;
  2. procedure TForm1.DecompressMyExternalXZfile(aFilename: String);
  3. var
  4.  InFileStream : TFileStream;
  5.  DecompressStream : TBzip2DecompressStream;
  6.  XZmemo: TMemo;
  7. begin
  8.   AddLogLine(FormatDateTime('YYYY-MM-DD HH:NN:SS',Now())+' - XZ decompression started', clBlack);
  9.   XZmemo := TMemo.Create(nil);
  10.   InFileStream := TFileStream.Create(aFilename, fmOpenRead);
  11.   DecompressStream := TBzip2DecompressStream.Create(InFileStream);
  12.   try
  13.     XZmemo.Lines.LoadFromStream(DecompressStream);
  14.     XZmemo.Lines.SaveToFile(copy(aFilename, 1, Length(aFilename)-3)); // Remove .xz from filename
  15.   finally
  16.     DecompressStream.Free;
  17.     InFileStream.Free;
  18.     XZmemo.Free;
  19.   end;
  20.   AddLogLine(FormatDateTime('YYYY-MM-DD HH:NN:SS',Now())+' - XZ decompressed', clBlack);
  21. end;
  22.  

The error I get is: Stream read error
Any help is really appreciated  :D
Title: Re: XZ files decompress
Post by: marcov on January 23, 2020, 05:46:46 pm
xz is a separate compressor and different from bzip2.

There seem to be external FPC/Delphi bindings, don't know the quality

https://github.com/delphiunderground/xz-examples-delphi
Title: Re: XZ files decompress
Post by: DanishMale on January 23, 2020, 06:21:17 pm
Perfect just what I needed .. Works perfect .. THAAAANKS!!!!
TinyPortal © 2005-2018