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

 

Compressing a file to memory

 


 

Easy Compression Library provides a memory stream interface with TECLMemoryStream class that can be easily used to compress and decompress a file to a memory.

 

Compressing a file to memory.

To compress a file to memory you need to perform the following 2 steps:

  1. Create an instance of TECLMemoryStream that will contain a compressed file with blank Password and with CompressionLevel parameter not equal to eclNone value, i.e. with one of the compression modes.
  2. Call LoadFromFile method of TECLMemoryStream to load and compress source file.
  3. Then you could directly access compressed data using CompressedDataStream property of TECLMemoryStream.

     

    Example:

    var

    CompFS: TECLMemoryStream;

    begin

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

    CompFS.LoadFromFile('c:\test.txt');

    { load compressed data }

    CompFS.CompressedDataStream.LoadFromFile('c:\test.ecl');

    { copy compressed data to a blob stream }

    BlobStream.CopyFrom(CompFS.CompressedDataStream, CompFS.CompressedDataStream.Size);

    CompFS.Free;

    end;

     

    Decompressing a file to memory.

    To decompress a file to memory you need to perform the following 3 steps:

    1. Create an instance of TECLMemoryStream for the compressed source file without parameters in constructor.
    2. Call LoadFromFile method of CompressedDataStream property of TECLMemoryStream to load compressed file.
    3. Set the value of CompressionLevel property of TECLMemoryStream to eclNone to decompress the data in memory.
    4.  

      Note:

      The step 3 is not required to access decompressed data in memory. For ECL streams, you almost always deal with the transparently decompressed data when you use methods and properties of the ECL streams.

       

      Example:

      var

      CompFS: TECLMemoryStream;

      begin

      CompFS := TECLMemoryStream.Create;

      CompFS.CompressedDataStream.LoadFromFile('c:\test.ecl');

      CompFS.CompressionLevel := eclNone;

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

      CompFS.Free;

      end;

       

        © 2003 - 2024 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Nov 13, 2024