Difference between revisions of "LMD VCL - ZLib support"

From LMD
Jump to: navigation, search
 
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{Head-StartRes}}
 +
 
== Introduction ==
 
== 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.  
+
Since 2007 series the LMD shared Runtime provides built-in ZLib library to compress/decompress any data. This is a native pascal solution and it doesn't require any external obj or dll files.
  
 
== Units ==
 
== Units ==
LMDZCommonUnit.pas - Common code and types for compress/decompress routines
+
* LMDZCommonUnit.pas - Common code and types for compress/decompress routines (raw ZLib api)
LMDZCompressUnit.pas - Unit that contain compression code (raw ZLib api)
+
* LMDZCompressUnit.pas - Unit that contain compression code (raw ZLib api)  
LMDZUncompressUnit.pas - Unit with uncompression 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.pas - TStream wrappers that provide interface to compress/decompress data directly into any TStream descendants.
  
 
== LMDZLib interface ==
 
== LMDZLib interface ==
Line 15: Line 17:
 
   ..., LMDZLib, ...;
 
   ..., LMDZLib, ...;
  
// old code
+
// code before using TLMDCompressionStream
 
...
 
...
 
var
 
var
Line 33: Line 35:
 
var
 
var
 
   LDataStream: TLMDCompressionStream;
 
   LDataStream: TLMDCompressionStream;
   LFileStr: TFileStream;
+
   LFileStream: TFileStream;
 +
begin
 +
  LFileStream := TFileStream.Create(FileName, fmCreate);
 +
  try
 +
    LDataStream := TLMDCompressionStream.Create(clDefault, LFileStream);
 +
    try
 +
      LDataStream.Write(FSomeData, FSizeOfSomeData);
 +
    finally
 +
      LDestStream.Free;
 +
    end;
 +
  finally
 +
    LFileStream.Free;
 +
  end;
 +
end;
 +
...
 +
</delphi>
 +
 
 +
TLMDDecompressionStream can be used as decompression layer for stream with compressed data. Example:
 +
 
 +
<delphi>
 +
uses
 +
  ..., LMDZLib, ...;
 +
 
 +
// code before using TLMDDecompressionStream
 +
...
 +
var
 +
  LDataStream: TFileStream;
 +
begin
 +
  LDataStream := TFileStream.Create(FileName, fmOpenRead);
 +
  try
 +
    LDataStream.Read(FSomeData, FSizeOfSomeData);
 +
  finally
 +
    LDataStream.Free;
 +
  end;
 +
end;
 +
...
 +
 
 +
// code with TLMDDecompressionStream
 +
...
 +
var
 +
  LDataStream: TLMDDecompressionStream;
 +
  LFileStream: TFileStream;
 
begin
 
begin
   LFileStr := TFileStream.Create(FileName, fmCreate);
+
   LFileStream := TFileStream.Create(FileName, fmOpenRead);
 
   try  
 
   try  
 +
    LDataStream := TLMDDecompressionStream.Create(LFileStream);
 
     try
 
     try
       LDataStream(FSomeData, FSizeOfSomeData);
+
       LDataStream.Read(FSomeData, FSizeOfSomeData);
 
     finally
 
     finally
 
       LDestStream.Free;
 
       LDestStream.Free;
 
     end;
 
     end;
 
   finally
 
   finally
     LFileStr.Free;
+
     LFileStream.Free;
 
   end;
 
   end;
 
end;
 
end;
 
...
 
...
 
</delphi>
 
</delphi>
 +
 +
As you can note required changes in your code are minimal.

Latest revision as of 13:52, 5 October 2008

<< Back to Getting started or Product Resources page

[edit]

Introduction

Since 2007 series the LMD shared Runtime provides built-in ZLib library to compress/decompress any data. This is a native pascal solution and it doesn't require any external obj or dll files.

Units

  • LMDZCommonUnit.pas - Common code and types for compress/decompress routines (raw ZLib api)
  • 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, ...;

// code before using TLMDCompressionStream ... 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.Write(FSomeData, FSizeOfSomeData);
   finally
     LDestStream.Free;
   end;
 finally
   LFileStream.Free;
 end;

end; ... </delphi>

TLMDDecompressionStream can be used as decompression layer for stream with compressed data. Example:

<delphi> uses

 ..., LMDZLib, ...;

// code before using TLMDDecompressionStream ... var

 LDataStream: TFileStream;

begin

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

end; ...

// code with TLMDDecompressionStream ... var

 LDataStream: TLMDDecompressionStream;
 LFileStream: TFileStream;

begin

 LFileStream := TFileStream.Create(FileName, fmOpenRead);
 try 
   LDataStream := TLMDDecompressionStream.Create(LFileStream); 
   try
     LDataStream.Read(FSomeData, FSizeOfSomeData);
   finally
     LDestStream.Free;
   end;
 finally
   LFileStream.Free;
 end;

end; ... </delphi>

As you can note required changes in your code are minimal.