WIP preserve large chat history recovery

This commit is contained in:
2026-10-18 15:03:18 +01:00
parent f91145001a
commit 998da0e7af
21 changed files with 1088 additions and 75 deletions
+13
View File
@@ -16,6 +16,9 @@ type boundedOutput struct {
}
func (b *boundedOutput) Write(p []byte) (int, error) {
if b.limit < 0 {
return b.Buffer.Write(p)
}
n := len(p)
remaining := b.limit - b.Len()
if n > remaining {
@@ -26,6 +29,16 @@ func (b *boundedOutput) Write(p []byte) (int, error) {
return n, nil
}
// WriteByte keeps byte-oriented history scanning under the same bound as Write;
// the embedded Buffer's promoted WriteByte would otherwise bypass the cap.
func (b *boundedOutput) WriteByte(c byte) error {
if b.limit >= 0 && b.Len() >= b.limit {
b.overflow = true
return nil
}
return b.Buffer.WriteByte(c)
}
// ReadFrom reads through the bounded Write so the cap applies even when
// os/exec's io.Copy selects a ReadFrom on the destination: without this the
// embedded bytes.Buffer's promoted ReadFrom would bypass Write and buffer the