update ReadBulkTo

This commit is contained in:
siddontang 2014-09-05 10:01:50 +08:00
parent c8e5e39f9d
commit 53ff437877
1 changed files with 7 additions and 2 deletions

View File

@ -29,7 +29,9 @@ func ReadLine(rb *bufio.Reader) ([]byte, error) {
func ReadBulkTo(rb *bufio.Reader, w io.Writer) error { func ReadBulkTo(rb *bufio.Reader, w io.Writer) error {
l, err := ReadLine(rb) l, err := ReadLine(rb)
if len(l) == 0 { if err != nil {
return err
} else if len(l) == 0 {
return errBulkFormat return errBulkFormat
} else if l[0] == '$' { } else if l[0] == '$' {
var n int var n int
@ -39,8 +41,11 @@ func ReadBulkTo(rb *bufio.Reader, w io.Writer) error {
} else if n == -1 { } else if n == -1 {
return nil return nil
} else { } else {
if _, err = io.CopyN(w, rb, int64(n)); err != nil { var nn int64
if nn, err = io.CopyN(w, rb, int64(n)); err != nil {
return err return err
} else if nn != int64(n) {
return io.ErrShortWrite
} }
if l, err = ReadLine(rb); err != nil { if l, err = ReadLine(rb); err != nil {