Skip to content

Commit 938c098

Browse files
committed
io: remove unnecessary EOF checks
1 parent ad43226 commit 938c098

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/io/io.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func LimitReader(r Reader, n int64) Reader { return &LimitedReader{R: r, N: n} }
467467
//
468468
// Negative values of N mean that the limit has been exceeded.
469469
// Read returns Err when more than N bytes are read from R.
470-
// If Err is nil or EOF, Read returns EOF instead.
470+
// If Err is nil, Read returns EOF.
471471
type LimitedReader struct {
472472
R Reader // underlying reader
473473
N int64 // max bytes remaining
@@ -492,15 +492,15 @@ func (l *LimitedReader) Read(p []byte) (n int, err error) {
492492
}
493493

494494
if l.N < 0 {
495-
if l.N == -1 && l.Err != nil && l.Err != EOF {
495+
if l.N == -1 && l.Err != nil {
496496
return 0, l.Err // limit was exceeded
497497
}
498498
return 0, EOF // stream was exactly N bytes, or already past limit
499499
}
500500

501501
// At limit (N == 0) - need to determine if stream has more data
502502

503-
if l.Err == nil || l.Err == EOF {
503+
if l.Err == nil {
504504
return 0, EOF
505505
}
506506

@@ -511,7 +511,7 @@ func (l *LimitedReader) Read(p []byte) (n int, err error) {
511511
// a byte from R, so we cache the result in N to avoid re-probing.
512512
var probe [1]byte
513513
probeN, probeErr := l.R.Read(probe[:])
514-
if probeN > 0 || (probeErr != nil && probeErr != EOF) {
514+
if probeN > 0 || probeErr != EOF {
515515
l.N = -1 // more data available, limit exceeded
516516
return 0, l.Err
517517
}

0 commit comments

Comments
 (0)