review feedback

This commit is contained in:
Paul Bellamy committed 2015-08-10 11:02:51 +01:00
1 parent 157910ec9a
commit 6d7e784c25
2 files changed
+25 -10

No files matched your search

+8 -10
View File
@@ -10,8 +10,6 @@ import (
"strconv"
)
const maxLineLength = 4096 // assumed <= bufio.defaultBufSize
var (
ErrLineTooLong = errors.New("header line too long")
ErrInvalidChunkLength = errors.New("invalid byte in chunk length")
@@ -89,22 +87,25 @@ func (cr *ChunkedReader) Err() error {
return cr.err
}
func (cr *ChunkedReader) beginChunk() (n uint64) {
func (cr *ChunkedReader) beginChunk() uint64 {
var (
line []byte
n uint64
)
// chunk-size CRLF
var line []byte
line, cr.err = readLine(cr.r)
if cr.err != nil {
return
return 0
}
n, cr.err = strconv.ParseUint(string(line), 16, 64)
if cr.err != nil {
cr.err = ErrInvalidChunkLength
}
return
return n
}
// Read a line of bytes (up to \n) from b.
// Give up if the line exceeds maxLineLength.
// Give up if the line exceeds the buffer size.
// The returned bytes are a pointer into storage in
// the bufio, so they are only valid until the next bufio read.
func readLine(b *bufio.Reader) (p []byte, err error) {
@@ -118,8 +119,5 @@ func readLine(b *bufio.Reader) (p []byte, err error) {
}
return nil, err
}
if len(p) >= maxLineLength {
return nil, ErrLineTooLong
}
return bytes.TrimRight(p, " \t\n\r"), nil
}