sliekens / Txt

A text parsing framework for .NET.
MIT License
2 stars 4 forks source link

PushbackInputStream.Position is wrong #5

Closed sliekens closed 9 years ago

sliekens commented 9 years ago

The Position property of the PushbackInputStream class always returns the position of the underlying stream. This is wrong: the value of the underlying stream's position should be reduced with the number of pushed-back bytes.

sliekens commented 9 years ago

This is not actually a bug, for the following two reasons.

  1. If the underlying stream supports seeking then the pushback buffer is never used, and the current position is guaranteed to be the same as the underlying stream.
  2. If the underlying stream does not support seeking then the documented behavior for Stream.Position is that it should throw System.NotSupportedException.

The only chance that this code could break is when the underlying stream does not correctly throw NotSupportException as documented. This would be a bug in the underlying stream class, not the PushbackInputStream class.

sliekens commented 9 years ago

It might be a good idea for PushbackInputStream.Position to implement the documented behavior instead of relying on the implementation of the underlying stream.