89 lines
2.3 KiB
ObjectPascal
89 lines
2.3 KiB
ObjectPascal
|
unit U_CompressionFun;
|
|||
|
|
|||
|
interface
|
|||
|
uses
|
|||
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
Dialogs, ComCtrls, ToolWin, ShlObj, cxShellCommon, cxControls,
|
|||
|
cxContainer, cxShellTreeView, cxShellListView, StdCtrls, BtnEdit,
|
|||
|
OleCtnrs, DB, ADODB,ZLib;
|
|||
|
|
|||
|
|
|||
|
procedure CompressionStream(var ASrcStream:TMemoryStream;ACompressionLevel:Integer = 2);
|
|||
|
procedure UnCompressionStream(var ASrcStream:TMemoryStream);
|
|||
|
|
|||
|
implementation
|
|||
|
uses
|
|||
|
U_iniparam;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
////////////////////////////////////////////////////
|
|||
|
///////ѹ<><D1B9><EFBFBD><EFBFBD>
|
|||
|
////////////////////////////////////////////////////
|
|||
|
procedure CompressionStream(var ASrcStream:TMemoryStream;ACompressionLevel:Integer = 2);
|
|||
|
var
|
|||
|
nDestStream:TMemoryStream;
|
|||
|
nTmpStream:TCompressionStream;
|
|||
|
nCompressionLevel:TCompressionLevel;
|
|||
|
begin
|
|||
|
ASrcStream.Position := 0;
|
|||
|
nDestStream := TMemoryStream.Create;
|
|||
|
try
|
|||
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
case ACompressionLevel of
|
|||
|
0:nCompressionLevel := clNone;
|
|||
|
1:nCompressionLevel := clFastest;
|
|||
|
2:nCompressionLevel := clDefault;
|
|||
|
3:nCompressionLevel := clMax;
|
|||
|
else
|
|||
|
nCompressionLevel := clMax;
|
|||
|
end;
|
|||
|
//<2F><>ʼѹ<CABC><D1B9>
|
|||
|
nTmpStream := TCompressionStream.Create(nCompressionLevel,nDestStream);
|
|||
|
try
|
|||
|
ASrcStream.SaveToStream(nTmpStream);
|
|||
|
finally
|
|||
|
nTmpStream.Free;//<2F>ͷź<CDB7>nDestStream<61>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
end;
|
|||
|
ASrcStream.Clear;
|
|||
|
ASrcStream.LoadFromStream(nDestStream);
|
|||
|
ASrcStream.Position := 0;
|
|||
|
finally
|
|||
|
nDestStream.Clear;
|
|||
|
nDestStream.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
////////////////////////////////////////////////////
|
|||
|
///////<2F><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
|
|||
|
////////////////////////////////////////////////////
|
|||
|
procedure UnCompressionStream(var ASrcStream:TMemoryStream);
|
|||
|
var
|
|||
|
nTmpStream:TDecompressionStream;
|
|||
|
nDestStream:TMemoryStream;
|
|||
|
nBuf: array[1..512] of Byte;
|
|||
|
nSrcCount: integer;
|
|||
|
begin
|
|||
|
ASrcStream.Position := 0;
|
|||
|
nDestStream := TMemoryStream.Create;
|
|||
|
nTmpStream := TDecompressionStream.Create(ASrcStream);
|
|||
|
try
|
|||
|
repeat
|
|||
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ʴ<EFBFBD>С
|
|||
|
nSrcCount := nTmpStream.Read(nBuf, SizeOf(nBuf));
|
|||
|
if nSrcCount > 0 then
|
|||
|
nDestStream.Write(nBuf, nSrcCount);
|
|||
|
until (nSrcCount = 0);
|
|||
|
ASrcStream.Clear;
|
|||
|
ASrcStream.LoadFromStream(nDestStream);
|
|||
|
ASrcStream.Position := 0;
|
|||
|
finally
|
|||
|
nDestStream.Clear;
|
|||
|
nDestStream.Free;
|
|||
|
nTmpStream.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
|
|||
|
end.
|