Recent

Author Topic: [SOLVED] XZ files decompress  (Read 819 times)

DanishMale

  • Jr. Member
  • **
  • Posts: 60
[SOLVED] XZ files decompress
« 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
« Last Edit: January 23, 2020, 06:21:36 pm by DanishMale »
Lazarus 2.0.6 x64 | FPC 3.0.4 | Windows 10 x64 | Windows Server 2019 x64 | OpenVix 5.3 (Linux) | MySQL Community Server 8.0 x64 | MariaDB 10.4.8 x64 | SQLite 3.16.2 x64 | PostgresSQL 12.0 x64

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8720
  • FPC developer.
Re: XZ files decompress
« Reply #1 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

DanishMale

  • Jr. Member
  • **
  • Posts: 60
Re: XZ files decompress
« Reply #2 on: January 23, 2020, 06:21:17 pm »
Perfect just what I needed .. Works perfect .. THAAAANKS!!!!
Lazarus 2.0.6 x64 | FPC 3.0.4 | Windows 10 x64 | Windows Server 2019 x64 | OpenVix 5.3 (Linux) | MySQL Community Server 8.0 x64 | MariaDB 10.4.8 x64 | SQLite 3.16.2 x64 | PostgresSQL 12.0 x64

 

TinyPortal © 2005-2018