🐛 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 Seek(Offset: Longint; Origin: Word): Longint; override;
|
||||
procedure Refresh; override;
|
||||
procedure Flush; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@@ -80,10 +81,14 @@ begin
|
||||
end;
|
||||
|
||||
procedure TBufferedStream.Flush;
|
||||
var
|
||||
memorySize: Int64;
|
||||
begin
|
||||
FBaseStream.Size := Size;
|
||||
memorySize := inherited GetSize;
|
||||
Position := 0;
|
||||
FBaseStream.Size := memorySize;
|
||||
FBaseStream.Position := 0;
|
||||
FBaseStream.CopyFrom(Self, 0);
|
||||
FBaseStream.CopyFrom(Self, memorySize);
|
||||
end;
|
||||
|
||||
function TBufferedStream.GetSize: Int64;
|
||||
@@ -136,9 +141,14 @@ end;
|
||||
function TBufferedReader.Write(const Buffer; Count: Integer): Longint;
|
||||
begin
|
||||
FBaseStream.Position := FReadBuffer.Position;
|
||||
FBaseStream.Write(Buffer, Count);
|
||||
Result := FBaseStream.Write(Buffer, Count);
|
||||
if Result < Count then Exit;
|
||||
Result := FReadBuffer.Write(Buffer, Count);
|
||||
end;
|
||||
|
||||
procedure TBufferedReader.Flush;
|
||||
begin
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user