WIP preserve large chat history recovery
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user