问题描述:

Very strange behavior

If I create a bufferedstream on top of a file and then seek to an offset I get a block of bytes back

If I move the debugger back to the seek and re-seek I get an extra two characters

I ve triple checked this

Can there possibly be a bug with this class ?

If I reseek back to position I expect to get the same - The file has not changed - I open it in read only mode and I seek based on Origin

Reproduction:

bufferedStream.Seek(100,0, 100)

bufferedStream.Reade(buffer, 0, 100)

is different to what you get from here

bufferedStream.Seek(100,0, 100)

bufferedStream.Reade(buffer, 0, 100)

网友答案:

First off, it is hard to know if they are the same without checking the return value fro Read - is it possible they are just choosing different chunks? (perfectly valid; it is your job to ensure you loop over Read until you have enough data, or EOF).

However, I wonder if a BOM is involved here - especially if you are sitting a text-reader on top of this. Simply, a reader expects the BOM at the start; so it may well hide it the first time through. But if you rewind the stream while using the same reader/decoder, it won't be expecting a BOM, so will try to report it as character data (or throw an error, depending on the configuraion).

相关阅读:
Top