🐛 Fix buffered stream flush losing data
Flush sized the base stream from its own overridden size, which delegates to the base stream, so appended data was truncated or the copy failed. Flushing a reader would have wiped the file; the reader writes through immediately and needs no flush. Write now also propagates short writes from the base stream.
This commit is contained in:
+13
-3
@@ -57,6 +57,7 @@ type
|
|||||||
function Read(var Buffer; Count: Longint): Longint; override;
|
function Read(var Buffer; Count: Longint): Longint; override;
|
||||||
function Seek(Offset: Longint; Origin: Word): Longint; override;
|
function Seek(Offset: Longint; Origin: Word): Longint; override;
|
||||||
procedure Refresh; override;
|
procedure Refresh; override;
|
||||||
|
procedure Flush; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@@ -80,10 +81,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TBufferedStream.Flush;
|
procedure TBufferedStream.Flush;
|
||||||
|
var
|
||||||
|
memorySize: Int64;
|
||||||
begin
|
begin
|
||||||
FBaseStream.Size := Size;
|
memorySize := inherited GetSize;
|
||||||
|
Position := 0;
|
||||||
|
FBaseStream.Size := memorySize;
|
||||||
FBaseStream.Position := 0;
|
FBaseStream.Position := 0;
|
||||||
FBaseStream.CopyFrom(Self, 0);
|
FBaseStream.CopyFrom(Self, memorySize);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBufferedStream.GetSize: Int64;
|
function TBufferedStream.GetSize: Int64;
|
||||||
@@ -136,9 +141,14 @@ end;
|
|||||||
function TBufferedReader.Write(const Buffer; Count: Integer): Longint;
|
function TBufferedReader.Write(const Buffer; Count: Integer): Longint;
|
||||||
begin
|
begin
|
||||||
FBaseStream.Position := FReadBuffer.Position;
|
FBaseStream.Position := FReadBuffer.Position;
|
||||||
FBaseStream.Write(Buffer, Count);
|
Result := FBaseStream.Write(Buffer, Count);
|
||||||
|
if Result < Count then Exit;
|
||||||
Result := FReadBuffer.Write(Buffer, Count);
|
Result := FReadBuffer.Write(Buffer, Count);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TBufferedReader.Flush;
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user