Compressing a file to file
Easy Compression Library provides a file stream interface with TECLFileStream class that can be easily used to compress and decompress a file to file.
Compressing a file to file.
To compress a file to file you need to perform the following 3 steps:
-
Create an instance of TECLFileStream for the destination compressed file with blank Password and with CompressionLevel parameter not equal to eclNone value, i.e. with one of the compression modes.
-
Call LoadFromFile method of TECLFileStream to load and compress source file.
-
Free the TECLFileStream object to close compressed file.
Example:
var
CompFS: TECLFileStream;
begin
CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmCreate, '', zlibFastest);
CompFS.LoadFromFile('c:\test.txt');
CompFS.Free;
end;
Decompressing a file to file.
To decompress a file to file you need to perform the following 3 steps:
-
Create an instance of TECLFileStream for the source compressed file with two parameters in constructor: FileName and Mode.
-
Call SaveToFile method of TECLFileStream to decompress data and save to the destination file.
-
Free the TECLFileStream object to close compressed file.
Example:
var
CompFS: TECLFileStream;
begin
CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmOpenRead or fmShareDenyNone);
CompFS.SaveToFile('c:\test_decomp.txt');
CompFS.Free;
end;
|