Skip to content

Instantly share code, notes, and snippets.

@alecthomas
Created May 19, 2014 18:17
Show Gist options
  • Save alecthomas/f33f594a71f0e2005f43 to your computer and use it in GitHub Desktop.
Save alecthomas/f33f594a71f0e2005f43 to your computer and use it in GitHub Desktop.
Make a normal io.Reader also function as an io.ByteReader
type ByteReader struct {
io.Reader
}
func (b *ByteReader) ReadByte() (byte, error) {
var buf [1]byte
if _, err := io.ReadFull(b, buf[:]); err != nil {
return 0, err
}
return buf[0], nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment