Created
May 19, 2014 18:17
-
-
Save alecthomas/f33f594a71f0e2005f43 to your computer and use it in GitHub Desktop.
Make a normal io.Reader also function as an io.ByteReader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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