Skip to content

Unify BufferedFileStreamStrategy seeking #78457

@adamsitnik

Description

@adamsitnik

Today while trying to find an answer to #78390 I've realized that BufferedFileStreamStrategy has two different approaches to seeking.

Seek provides a smart way of seeking that tries to avoid losing the buffered data if possible:

// If the offset of the updated seek pointer in the buffer is still legal, then we can keep using the buffer:
if (0 <= readPos && readPos < _readLen)
{
_readPos = (int)readPos;
// Adjust the seek pointer of the underlying stream to reflect the amount of useful bytes in the read buffer:
_strategy.Seek(_readLen - _readPos, SeekOrigin.Current);
}
else
{ // The offset of the updated seek pointer is not a legal offset. Loose the buffer.
_readPos = _readLen = 0;
}

While Position setter is plain simple and always loses the buffered data:

set
{
if (_writePos > 0)
{
FlushWrite();
}
_readPos = 0;
_readLen = 0;
_strategy.Position = value;
}

Position should be "smart" too and most likely just delegate the work to Seek

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IOgood first issueIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions