109 lines
3.0 KiB
ObjectPascal
109 lines
3.0 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);
|
|
procedure GetFileInfo(mFile:string;var mfileSize:integer;var CreationTime:tdatetime;var WriteTime:tdatetime);
|
|
function CovFileDate(Fd:_FileTime):TDateTime;
|
|
|
|
implementation
|
|
|
|
|
|
|
|
procedure GetFileInfo(mFile:string;var mfileSize:integer;var CreationTime:tdatetime;var WriteTime:tdatetime);
|
|
var
|
|
vSearchRec: TSearchRec;
|
|
begin
|
|
FindFirst(mFile,faAnyFile,vSearchRec);
|
|
mfileSize:=vSearchRec.Size;
|
|
CreationTime:=CovFileDate(vSearchRec.FindData.ftCreationTime);//创建时间
|
|
//vSearchRec.FindData.ftLastAccessTime//访问时间
|
|
WriteTime:=CovFileDate(vSearchRec.FindData.ftLastWriteTime);//修改时间
|
|
FindClose(vSearchRec);
|
|
end;
|
|
function CovFileDate(Fd:_FileTime):TDateTime;
|
|
var
|
|
Tct:_SystemTime;
|
|
Temp:_FileTime;
|
|
begin
|
|
FileTimeToLocalFileTime(Fd,Temp);
|
|
FileTimeToSystemTime(Temp,Tct);
|
|
CovFileDate:=SystemTimeToDateTime(Tct);
|
|
end;
|
|
|
|
////////////////////////////////////////////////////
|
|
///////压缩流
|
|
////////////////////////////////////////////////////
|
|
procedure CompressionStream(var ASrcStream:TMemoryStream;ACompressionLevel:Integer = 2);
|
|
var
|
|
nDestStream:TMemoryStream;
|
|
nTmpStream:TCompressionStream;
|
|
nCompressionLevel:TCompressionLevel;
|
|
begin
|
|
ASrcStream.Position := 0;
|
|
nDestStream := TMemoryStream.Create;
|
|
try
|
|
//级别
|
|
case ACompressionLevel of
|
|
0:nCompressionLevel := clNone;
|
|
1:nCompressionLevel := clFastest;
|
|
2:nCompressionLevel := clDefault;
|
|
3:nCompressionLevel := clMax;
|
|
else
|
|
nCompressionLevel := clMax;
|
|
end;
|
|
//开始压缩
|
|
nTmpStream := TCompressionStream.Create(nCompressionLevel,nDestStream);
|
|
try
|
|
ASrcStream.SaveToStream(nTmpStream);
|
|
finally
|
|
nTmpStream.Free;//释放后nDestStream才会有数据
|
|
end;
|
|
ASrcStream.Clear;
|
|
ASrcStream.LoadFromStream(nDestStream);
|
|
ASrcStream.Position := 0;
|
|
finally
|
|
nDestStream.Clear;
|
|
nDestStream.Free;
|
|
end;
|
|
end;
|
|
////////////////////////////////////////////////////
|
|
///////解压缩流
|
|
////////////////////////////////////////////////////
|
|
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
|
|
//读入实际大小
|
|
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.
|