I found in this thread link of the delphi-zip library that has implementation of LZMA. But I can't make proper use of Decompression from it. Can some one write a little decompression sample for me, using this library?
Here is my code, it works for compression but didn't work for decompression and return 0 size
uses System.Zip.LZMA;
....
procedure TForm2.CompressProgress(Sender: TObject; const aPosition, aSize, aCompressedSize: UInt64);
begin
end;
procedure TForm2.DecompressProgress(Sender: TObject; const aPosition, aSize: UInt64);
begin
end;
procedure TForm2.CompressButton1Click(Sender: TObject);
var LZI: TLZMAEncoderStream; OutStream, InStream: TMemoryStream;
begin
OutStream:= TMemoryStream.Create;
LZI := TLZMAEncoderStream.Create(OutStream, CompressProgress);
InStream:= TMemoryStream.Create;
InStream.LoadFromFile('1.exe');
InStream.Position := 0;
LZI.Write(InStream, InStream.Size);
OutStream.Position := 0;
OutStream.SaveToFile('1.exe.lzma');
InStream.Free;
OutStream.Free;
LZI.Free;
end;
procedure TForm2.DecompressButton2Click(Sender: TObject);
var Deca: TLZMADecoderStream; Str1: TMemoryStream; S2 : TBytesStream; J, I: Cardinal;
begin
I := 0;
Str1 := TMemoryStream.Create;
Str1.LoadFromFile('1.exe.lzma');
Str1.Position := 0;
Deca:= TLZMADecoderStream.Create(Str1, DecompressProgress);
S2 := TBytesStream.Create;
J := Deca.Read(S2.Bytes, 0, i);
Caption := IntToStr(J);
S2.Position := 0;
S2.SaveToFile('1.exe');
Deca.Free;
Str1.Free;
S2.Free;
end;
also I tried do like this, but still not work
procedure TForm2.Button2Click(Sender: TObject);
var Deca: TLZMADecoderStream; Str1 : TMemoryStream; S2:TBytesStream; J, I: Cardinal;
begin
I := 0;
Str1 := TMemoryStream.Create;
Str1.LoadFromFile('1.exe.lzma');
Str1.Position := 0;
Deca:= TLZMADecoderStream.Create(Str1, DeProgress);
S2 := TBytesStream.Create;
Deca.Position := 0;
J := Deca.Read(S2.Bytes, 0, Deca.Size);
Caption := IntToStr(J);
S2.Position := 0;
S2.SaveToFile('Dec0.exe');
Deca.Free;
Str1.Free;
S2.Free;
end;