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

 

Replacing standard streams

 


 

Easy Compression Library provides a very easy in use replacements of TFileStream, TMemoryStream and other TStream descendants with advanced compression/decompression and encryption capabilities.

 

With Easy Compression Library replacing TFileStream and TMemoryStream with compression/decompression capabilities is a very simple task.

 

At first you should add the EasyCompression unit to the uses section of your application unit.

Then you may perform search and replace in your application code and replace 'TFileStream' to the 'TECLFileStream'. If you stop at this point, recompile and run your project then you won't see any difference from the original behavior of your program.

 

Next you can pass the compression level and password to TECLFileStream or only compression level to TECLMemoryStream constructor parameters.

 

Moreover you can add a progress indication event handler, get compression rate and use advanced functions such as SaveToFile/LoadFromFile and SaveToStream/LoadFromStream.

 

Assume that firstly we used the TFileStream for data access and now we’d like our file to be compressed and encrypted. The following example illustrates the differences in application code when TECLFileStream is used instead of TFileStream.

Example:

var

fs: TFileStream;

inBuf,outBuf: PChar;

offset,inSize,outSize: Integer;

begin

{buffers are allocated, necessary offsets and sizes are set}

 

{ let’s create file }

fs := TFileStream.Create(‘test.dat’,fmCreate);

 

 

{ write some data}

fs.WriteBuffer(outBuf^,outSize);

 

{ seek to needed position }

fs.Seek(offset, soFromBeginning);

 

{ read some data }

fs.ReadBuffer(inBuf^,inSize);

 

{close file }

fs.Free;

end;

var

fs: TECLFileStream;

inBuf,outBuf: PChar;

offset,inSize,outSize: Integer;

begin

{buffers are allocated, necessary offsets and sizes are set}

 

{ let’s create compressed and encrypted file}

fs := TECLFileStream.Create(‘test.dat’, fmCreate, ’Password’, eclFastest);

 

{ write some data }

fs.WriteBuffer(outBuf^,outSize);

 

{ seek to needed position }

fs.Seek(offset, soFromBeginning);

 

{ read some data }

fs.ReadBuffer(inBuf^,inSize);

 

{close file }

fs.Free;

end;

 

 

        © 2003 - 2017 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Jun 26, 2017