Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nwaples/rardecode
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.1.0
Choose a base ref
...
head repository: nwaples/rardecode
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.1.1
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Feb 22, 2025

  1. dont Peek bufio.Reader > buffer size

    bufio.ErrBufferFull was masking the real error.
    nwaples committed Feb 22, 2025
    Copy the full SHA
    d622dfb View commit details
  2. Copy the full SHA
    14816ae View commit details
Showing with 12 additions and 14 deletions.
  1. +2 −4 reader.go
  2. +10 −10 volume.go
6 changes: 2 additions & 4 deletions reader.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package rardecode

import (
"bufio"
"bytes"
"crypto/hmac"
"crypto/sha256"
"errors"
"hash"
"io"
"math"
"os"
"time"
)
@@ -229,12 +227,12 @@ func (f *packedFileReader) bytes() ([]byte, error) {
return nil, err
}
}
n := int(min(f.n, math.MaxInt))
n := int(min(f.n, int64(f.v.br.Size())))
if k := f.v.br.Buffered(); k > 0 {
n = min(k, n)
} else {
b, err := f.v.peek(n)
if err != nil && err != bufio.ErrBufferFull {
if err != nil {
return nil, err
}
n = len(b)
20 changes: 10 additions & 10 deletions volume.go
Original file line number Diff line number Diff line change
@@ -170,21 +170,21 @@ func (v *volume) peek(n int) ([]byte, error) {
}

func (v *volume) readSlice(n int) ([]byte, error) {
b, err := v.br.Peek(n)
if err == nil {
if n <= v.br.Size() {
b, err := v.br.Peek(n)
if err != nil {
if err == io.EOF && len(b) > 0 {
err = io.ErrUnexpectedEOF
}
return nil, err
}
n, err = v.br.Discard(n)
v.off += int64(n)
return b[:n:n], err
}
if err != bufio.ErrBufferFull {
if err == io.EOF && len(b) > 0 {
err = io.ErrUnexpectedEOF
}
return nil, err
}
// bufio.Reader buffer is too small, create a new slice and copy to it
b = make([]byte, n)
if _, err = io.ReadFull(v.br, b); err != nil {
b := make([]byte, n)
if _, err := io.ReadFull(v.br, b); err != nil {
return nil, err
}
v.off += int64(n)