避免出现err==nil&&n==0的情况

This commit is contained in:
ioito
2019-05-31 11:59:08 +08:00
parent 95a911eb69
commit c8b1fd16ec
2 changed files with 9 additions and 11 deletions

View File

@@ -1,13 +1,13 @@
package multipart
import (
"io"
"bytes"
"crypto/rand"
"fmt"
"io"
"net/textproto"
"strings"
"bytes"
"sort"
"strings"
)
type SReader struct {
@@ -88,12 +88,10 @@ func (r *SReader) Read(p []byte) (n int, err error) {
if read < len(p) && !r.bodyEof {
n, err := r.body.Read(p[read:])
read += n
if err != nil {
if err == io.EOF {
r.bodyEof = true
} else {
return read, err
}
if err == io.EOF || n == 0 {
r.bodyEof = true
} else {
return read, err
}
}
for read < len(p) && r.tailOffset < len(r.tail) {

View File

@@ -1,10 +1,10 @@
package multipart
import (
"testing"
"strings"
"bytes"
"io"
"strings"
"testing"
)
func TestReader(t *testing.T) {