Creating compressed memory stream
With Easy Compression Library you could easily compress and encrypt data in memory using a stream interface.
To create an instance of TECLMemoryStream you should call TECLMemoryStream.Create with two optional parameters: Password and CompressionLevel.
When the Password parameter is not blank, it is used to encrypt the file (except the case when CompressionLevel is eclNone).
CompressionLevel indicates the algorithm and mode that is used for compression.
When CompressionLevel is eclNone, TECLMemoryStream is equal to TMemoryStream.
The following example illustrates how to encrypted and compress test.txt in memory and save the compressed data to disk.
Example:
var
CompMS: TECLMemoryStream;
begin
CompMS := TECLMemoryStream.Create('Password', bzipMax);
CompMS.LoadFromFile('c:\test.txt');
ShowMessage('The size of compressed data is: ' + IntToStr(CompMS.CompressedDataStream.Size));
CompMS.CompressedDataStream.SaveToFile('c:\test.ecl');
CompMS.Free;
end;
|