function DeCompressFile(InputFileName, OutputFileName:
string): boolean;
var
CompressInputStream: TFileStream;
CompressOutputStream: TStreamProgressAdapter;
DeCompressionStream:
ZLib.TDeCompressionStream;
CProgress: TCommonProgress;
Buf:
array[0..4095]
of Byte;
Count: Integer;
begin
result := true;
CompressInputStream := TFileStream.Create(InputFileName, fmOpenRead);
try
CompressOutputStream := TStreamProgressAdapter.Create(TFileStream.Create(OutputFileName, fmCreate), 0);
try
DecompressionStream := TDecompressionStream.Create(CompressInputStream);
try
CProgress := TCommonProgress.Create;
try
try
CompressOutputStream.OnProgress := CProgress.Progress;
while true
do
begin
Count := DeCompressionStream.
Read(Buf[0], SizeOf(Buf));
if Count = 0
then
break
else
CompressOutputStream.
Write(Buf[0], Count);
end;
except
on E:
Exception do
begin
result := false;
if not (E
is EAbort)
then raise;
end;
end;
finally
CProgress.Free;
end;
finally
DecompressionStream.Free;
end;
finally
CompressOutputStream.Free;
end;
finally
CompressInputStream.Free;
end;
end;
function CompressFile(InputFileName, OutputFileName:
string): boolean;
var
CompressInputStream: TStreamProgressAdapter;
CompressOutputStream: TFileStream;
CompressionStream:
ZLib.TCompressionStream;
CProgress: TCommonProgress;
begin
result := true;
CompressInputStream := TStreamProgressAdapter.Create(TFileStream.Create(InputFileName, fmOpenRead), 0);
try
CompressOutputStream := TFileStream.Create(OutputFileName, fmCreate);
try
CompressionStream := TCompressionStream.Create(clMax, CompressOutputStream);
try
CProgress := TCommonProgress.Create;
try
try
CompressInputStream.OnProgress := CProgress.Progress;
CompressionStream.CopyFrom(CompressInputStream, CompressInputStream.Size);
except
on E:
Exception do
begin
result := false;
if not (E
is EAbort)
then raise;
end;
end;
finally
CProgress.Free;
end;
finally
CompressionStream.Free;
end;
finally
CompressOutputStream.Free;
end;
finally
CompressInputStream.Free;
end;
end;