The TStream.ReadBuffer and TStream.WriteBuffer methods have changed the Count parameter type to NativeInt.

Changed the implementation of ReadBuffer, WriteBuffer so that the size of the blocks when calling Read and Write does not exceed High(Longint).
Notes:
- Thanks to this change, for example, a file larger than 2GB can be loaded into TMemoryStream.
- The fact that the Count parameter has the NativeInt type is compatible with the latest versions of Delphi.
This commit is contained in:
Sergey Larin 2021-08-06 10:54:26 +03:00 committed by Michael Van Canneyt
parent fbc65314b9
commit e27ea76b88
2 changed files with 22 additions and 22 deletions

View File

@ -999,7 +999,7 @@ type
function ReadData(var Buffer: TExtended80Rec): NativeInt; overload;
function ReadData(var Buffer: TExtended80Rec; Count: NativeInt): NativeInt; overload;
{$ENDIF}
procedure ReadBuffer(var Buffer; Count: Longint);
procedure ReadBuffer(var Buffer; Count: NativeInt);
procedure ReadBuffer(var Buffer: TBytes; Count: NativeInt); overload;
procedure ReadBuffer(var Buffer: TBytes; Offset, Count: NativeInt); overload;
@ -1035,7 +1035,7 @@ type
procedure ReadBufferData(var Buffer: TExtended80Rec); overload;
procedure ReadBufferData(var Buffer: TExtended80Rec; Count: NativeInt); overload;
{$ENDIF}
procedure WriteBuffer(const Buffer; Count: Longint);
procedure WriteBuffer(const Buffer; Count: NativeInt);
procedure WriteBuffer(const Buffer: TBytes; Count: NativeInt); overload;
procedure WriteBuffer(const Buffer: TBytes; Offset, Count: NativeInt); overload;

View File

@ -404,19 +404,19 @@ begin
end;
{$ENDIF}
procedure TStream.ReadBuffer(var Buffer; Count: Longint);
Var
r,t : longint;
procedure TStream.ReadBuffer(var Buffer; Count: NativeInt);
var
r,t: NativeInt;
begin
t:=0;
repeat
r:=Read(PByte(@Buffer)[t],Count-t);
r:=Count-t;
if r>High(Longint) then r:=High(Longint);
r:=Read(PByte(@Buffer)[t],r);
inc(t,r);
until (t=Count) or (r<=0);
if (t<Count) then
Raise EReadError.Create(SReadError);
raise EReadError.Create(SReadError);
end;
procedure TStream.ReadBuffer(var Buffer: TBytes; Count: NativeInt);
@ -581,20 +581,20 @@ begin
end;
{$ENDIF}
procedure TStream.WriteBuffer(const Buffer; Count: Longint);
procedure TStream.WriteBuffer(const Buffer; Count: NativeInt);
var
r,t : Longint;
begin
T:=0;
Repeat
r:=Write(PByte(@Buffer)[t],Count-t);
inc(t,r);
Until (t=count) or (r<=0);
if (t<Count) then
Raise EWriteError.Create(SWriteError);
end;
w,t: NativeInt;
begin
t:=0;
repeat
w:=Count-t;
if w>High(Longint) then w:=High(Longint);
w:=Write(PByte(@Buffer)[t],w);
inc(t,w);
until (t=count) or (w<=0);
if (t<Count) then
raise EWriteError.Create(SWriteError);
end;
procedure TStream.WriteBuffer(const Buffer: TBytes; Count: NativeInt);
begin