I am working on improving a stream reader class that uses a BinaryReader
. It consists of a while loop that uses .PeekChar()
to check if more data exists to continue processing.
The very first operation is a .ReadInt32()
which reads 4 bytes. What if PeekChar
only "saw" one byte (or one bit)? This doesn't seem like a reliable way of checking for EOF.
The BinaryReader
is constructed using its default parameters, which as I understand it, uses UTF8 as the default encoding. I assume that .PeekChar()
checks for 8 bits but I really am not sure.
How many bits does .PeekChar()
look for? (and what are some alternate methods to checking for EOF?)
ReadInt32
, I'd say that you have an error condition and not an EOF condition... – AcrilanSystem.Int32
, wouldn't it read 32 bits? – Swetlana