Delphi Database, Delphi Components from ComponentAce
Products Download Order Contact us
/img/help/home.gif /img/help/prev.gif /img/help/next.gif


Accessing compressed data



Easy Compression Library streams (TECLFileStream, TECLMemoryStream, TECLStream) compress and decompress data on the fly, so when you get TECLFileStream.Size, you see a size of decompressed file, because the file is compressed/decompressed transparently.


This technology significantly simplifies dealing with the points specific for compression, and after specifying CompressionLevel you may work with ECL streams as with usual streams and don't care of compression.


But sometimes, the direct access to the compressed data is required. For example if you want to compress data in memory using TECLMemoryStream and then write this compressed data to a special place in a file or to transmit this data by packets over the internet or a network.


Easy Compression Library provides an easy way to get the direct access to compressed (encrypted) data in ECL streams through its CompressedDataStream property.

Use this property as a stream to access compressed data directly.


The following example illustrates how to compress test.txt in memory, save the compressed data to a file with special offset, load again and then access the transparently decompressed data.



CompMS: TECLMemoryStream;

FS: TFileStream;


{ create compressed memory stream }

CompMS := TECLMemoryStream.Create('', ppmMax);

{ load and compress test.txt }


{ save compressed data to 'custom.dat' with offset=10 }

FS := TFileStream.Create('custom.dat', fmCreate);

FS.Position := 10;


{ close streams }




{ create ECL memory stream for compressed data }

CompMS := TECLMemoryStream.Create;

{ load data from the file 'custom.dat' with offset }

FS := TFileStream.Create('custom.dat', fmOpenReadWrite or fmShareDenyNone);

FS.Position := 10;

CompMS.CompressedDataStream.CopyFrom(FS, FS.Size-10);

{ access transparently decompressed data }

ShowMessage('The size of decompressed data is: ' + IntToStr(CompMS.Size));

{ close streams }





        © 2003 - 2017 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Jan 17, 2017