What is the most efficient way to skip a certain number of bytes in any Stream ?
If possible, I would like to get or throw an EndOfStreamException when trying to skip the end of the stream.
I am writing a custom Reader stream for primitive ISO 9660 data types, and this can include many omissions in search and non-selectable streams, both small numbers (4) and large numbers (2048) bytes. Therefore, I want to implement the Skip(int count) method, which is slightly more efficient than reading and discarding missed bytes.
For example, in a seekable stream , I could make stream.Position += 4 , but that does not throw an EndOfStreamException when searching at the end of the stream, and I don't know how to check this without reading something. For streams that are not searchable, setting Position is not even an option, but reading and then discarding a large number of bytes and allocating unused byte arrays seems very wasteful.
source share