From 5e92d58a6eb9f8a2251a96ec9522978508e799f8 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 14 Nov 2026 22:35:26 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20buffered=20stream=20flush?= =?UTF-8?q?=20losing=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- UBufferedStreams.pas | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/UBufferedStreams.pas b/UBufferedStreams.pas index 7799b4f..687c032 100644 --- a/UBufferedStreams.pas +++ b/UBufferedStreams.pas @@ -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.