//带压缩的存储
var
SS:TStream;
begin
FieldByName('wjm').AsString:=PCFileName;
SS:=CreateCompressStreamFromFile(PCFile);
TBLOBField(Table1.FieldByName('files')).LoadFromStream(SS);
SS.Free;
end;
//////////////////////////////////////////////////////////////
unit ClientUtils;
interface
uses SysUtils, Classes, DB, ZLib;
function CreateCompressStreamFromFile(FileName:String):TStream;
function CreateDecompressStreamFromField(Field:TBLOBField):TMemoryStream;
implementation
function CreateCompressStreamFromFile(FileName:String):TStream;
var
CS:TCompressionStream;
FS:TFileStream;
Size:Integer;
begin
Result:=TMemoryStream.Create;
FS:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
Size:=FS.Size;
Result.Write(Size,SizeOf(Size));
CS:=TCompressionStream.Create(clFastest,Result);
try
CS.CopyFrom(FS,FS.Size)
finally
CS.Free;
FS.Free;
end;
Result.Position:=0;
end;
function CreateDecompressStreamFromField(Field:TBLOBField):TMemoryStream;
var
DS:TDecompressionStream;
SS:TMemoryStream;
Size:Integer;
begin
Result:=TMemoryStream.Create;
SS:=TMemoryStream.Create;
try
Field.SaveToStream(SS);
SS.Position:=0;
if SS.Size>0 then
begin
SS.Read(Size,SizeOf(Size));
if Size>0 then
begin
Result.Size:=Size;
DecompressToUserBuf(Pointer(INteger(SS.Memory)+SizeOf(Size)),SS.Size-SizeOf(Size),Result.Memory,Size);
{
DS:=TDecompressionStream.Create(SS);
try
Result.CopyFrom(DS,Size);
finally
DS.Free;
end;
}
end;
end;
finally
SS.Free;
end;
//Result.Position:=0;
end;
end.