Difference between revisions of "LMD VCL - ZLib support"

From LMD
Jump to: navigation, search
 
(LMDZLib interface)
Line 33: Line 33:
 
var
 
var
 
   LDataStream: TLMDCompressionStream;
 
   LDataStream: TLMDCompressionStream;
   LFileStr: TFileStream;
+
   LFileStream: TFileStream;
 
begin
 
begin
   LFileStr := TFileStream.Create(FileName, fmCreate);
+
   LFileStream := TFileStream.Create(FileName, fmCreate);
 
   try  
 
   try  
 +
    LDataStream := TLMDCompressionStream.Create(clDefault, LFileStream);
 
     try
 
     try
 
       LDataStream(FSomeData, FSizeOfSomeData);
 
       LDataStream(FSomeData, FSizeOfSomeData);
Line 43: Line 44:
 
     end;
 
     end;
 
   finally
 
   finally
     LFileStr.Free;
+
     LFileStream.Free;
 
   end;
 
   end;
 
end;
 
end;
 
...
 
...
 
</delphi>
 
</delphi>

Revision as of 13:58, 17 July 2007

Introduction

LMD 2k7 has built in ZLib library to compress/uncompress any data. This is native pascal solution it doesn't require any external obj or dll files.

Units

LMDZCommonUnit.pas - Common code and types for compress/decompress routines LMDZCompressUnit.pas - Unit that contain compression code (raw ZLib api) LMDZUncompressUnit.pas - Unit with uncompression code (raw ZLib api) LMDZLib.pas - TStream wrappers that provide interface to compress/decompress data directly into any TStream descendants.

LMDZLib interface

TLMDCompressionStream wrapper class that compress data directly to any TStream descendant, and has transparent interface that compatible with TStream, so you can easily add compression for exists application. Example:

<delphi> uses

 ..., LMDZLib, ...;

// old code ... var

 LDataStream: TFileStream;

begin

 LDataStream := TFileStream.Create(FileName, fmCreate);
 try
   LDataStream(FSomeData, FSizeOfSomeData);
 finally
   LDataStream.Free;
 end;

end; ...

// code with TLMDCompressionStream ... var

 LDataStream: TLMDCompressionStream;
 LFileStream: TFileStream;

begin

 LFileStream := TFileStream.Create(FileName, fmCreate);
 try 
   LDataStream := TLMDCompressionStream.Create(clDefault, LFileStream); 
   try
     LDataStream(FSomeData, FSizeOfSomeData);
   finally
     LDestStream.Free;
   end;
 finally
   LFileStream.Free;
 end;

end; ... </delphi>