eof

  • Thread starter Thread starter Juan Marcial
  • Start date Start date
J

Juan Marcial

does how to know end of file (eof) while reading a binary stream that does
not support seeking?

that is, is not valid:
while (br.PeekChar() > 0) { ... }
 
Juan said:
does how to know end of file (eof) while reading a binary stream that does
not support seeking?

that is, is not valid:
while (br.PeekChar() > 0) { ... }

Any Read method and test on return status. Read() returns -1 if
EOF.

Arne
 
Any Read method and test on return status. Read() returns -1 if
EOF.

It returns 0 at the end-of-stream, actually. But yes, checking the return
value from the Read() method is the correct way.

Pete
 
Peter Duniho said:
It returns 0 at the end-of-stream, actually. But yes, checking the return
value from the Read() method is the correct way.

Not in the case of BinaryReader, which I strongly suspect is the type
the OP is using, given the use of PeekChar and br as a variable name.

BinaryReader isn't a brilliantly designed API - I would certainly have
*guessed* that BinaryReader.Read would either read a single *byte* or a
buffer of bytes. Instead it reads a single *character* based on the
current encoding. For something which has "binary" in the name, it
certainly seems somewhat biased towards text...
 
Peter said:
It returns 0 at the end-of-stream, actually. But yes, checking the
return value from the Read() method is the correct way.

Docs says:

#Return Value
#The next character from the input stream, or -1 if no characters are
#currently available.

Arne
 
Not in the case of BinaryReader, which I strongly suspect is the type
the OP is using, given the use of PeekChar and br as a variable name.

Ah. The OP wrote "stream", so naturally I assumed he was using a stream.
But I agree, if you look more closely at the code he posted, BinaryReader
seems more likely.

Guess that'll teach me to trust what someone writes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top