function StreamToDataPackage(const AStream: TStream): OleVariant;
var
pData: Pointer;
begin
Assert(AStream <> nil);
Result := Null;
with AStream do
begin
if Size = 0 then
Exit;
Result := VarArrayCreate([0, Size-1], varByte);
pData := VarArrayLock(Result);
try
Position := 0;
Read(pData^, Size);
finally
VarArrayUnlock(Result);
end;
end;
end;
procedure DataPackageToStream(const ADataPackage: OleVariant
AStream: TStream);
var
p: Pointer;
begin
Assert(AStream <> nil);
with AStream do
begin
if ADataPackage = Null then
begin
Size := 0;
Exit;
end;
Position := 0;
Size := VarArrayHighBound(ADataPackage, 1) - VarArrayLowBound(ADataPackage, 1) + 1;
p := VarArrayLock(ADataPackage);
try
Write(p^, Size);
finally
VarArrayUnlock(ADataPackage);
end;
Position := 0;
end;
end;