diff --git a/codec/codecutil/byte-scanner.go b/codec/codecutil/byte-scanner.go index 1a09d29f..122964cb 100644 --- a/codec/codecutil/byte-scanner.go +++ b/codec/codecutil/byte-scanner.go @@ -1,6 +1,6 @@ /* NAME - scanner.go + byte-scanner.go AUTHOR Dan Kortschak @@ -26,8 +26,8 @@ package bytescan import "io" -// Scanner is a byte scanner. -type Scanner struct { +// ByteScanner is a byte scanner. +type ByteScanner struct { buf []byte off int @@ -35,15 +35,15 @@ type Scanner struct { r io.Reader } -// NewScanner returns a scanner initialised with an io.Reader and a read buffer. -func NewScanner(r io.Reader, buf []byte) *Scanner { - return &Scanner{r: r, buf: buf[:0]} +// NewByteScanner returns a scanner initialised with an io.Reader and a read buffer. +func NewByteScanner(r io.Reader, buf []byte) *ByteScanner { + return &ByteScanner{r: r, buf: buf[:0]} } // ScanUntil scans the scanner's underlying io.Reader until a delim byte // has been read, appending all read bytes to dst. The resulting appended data, // the last read byte and whether the last read byte was the delimiter. -func (c *Scanner) ScanUntil(dst []byte, delim byte) (res []byte, b byte, err error) { +func (c *ByteScanner) ScanUntil(dst []byte, delim byte) (res []byte, b byte, err error) { outer: for { var i int @@ -65,7 +65,7 @@ outer: } // ReadByte is an unexported ReadByte. -func (c *Scanner) ReadByte() (byte, error) { +func (c *ByteScanner) ReadByte() (byte, error) { if c.off >= len(c.buf) { err := c.reload() if err != nil { @@ -78,7 +78,7 @@ func (c *Scanner) ReadByte() (byte, error) { } // reload re-fills the scanner's buffer. -func (c *Scanner) reload() error { +func (c *ByteScanner) reload() error { n, err := c.r.Read(c.buf[:cap(c.buf)]) c.buf = c.buf[:n] if err != nil { diff --git a/codec/codecutil/byte-scanner_test.go b/codec/codecutil/byte-scanner_test.go index 5042b1ce..40770d59 100644 --- a/codec/codecutil/byte-scanner_test.go +++ b/codec/codecutil/byte-scanner_test.go @@ -1,6 +1,6 @@ /* NAME - scanner_test.go + byte-scanner_test.go DESCRIPTION See Readme.md @@ -46,7 +46,7 @@ func TestScannerReadByte(t *testing.T) { data := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") for _, size := range []int{1, 2, 8, 1 << 10} { - r := NewScanner(bytes.NewReader(data), make([]byte, size)) + r := NewByteScanner(bytes.NewReader(data), make([]byte, size)) var got []byte for { b, err := r.ReadByte() @@ -65,7 +65,7 @@ func TestScannerScanUntilZero(t *testing.T) { data := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit,\x00 sed do eiusmod tempor incididunt ut \x00labore et dolore magna aliqua.") for _, size := range []int{1, 2, 8, 1 << 10} { - r := NewScanner(bytes.NewReader(data), make([]byte, size)) + r := NewByteScanner(bytes.NewReader(data), make([]byte, size)) var got [][]byte for { buf, _, err := r.ScanUntil(nil, 0x0)