public override long Seek(long pos, SeekOrigin origin) {
if (origin == SeekOrigin.Current) {
if (_pushBackPreservesPosition) {
pos -= ReadAheadCount;
} else {
origin = SeekOrigin.Begin;
pos += Position;
}
}
// try seek first, it may fail and we shouldn't change the buffer if so:
var result = _stream.Seek(pos, origin);
// TODO: we might keep the buffered data if we seek within the buffered data (but not in pushed back data):
// clear any buffer content (including ungetc):
_bufferStart = _bufferCount = _pushedBackCount = 0;
return result;
}