Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CLP ReaderInterface implementations to achieve consistent seek behaviour. #628

Open
gibber9809 opened this issue Dec 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@gibber9809
Copy link
Contributor

Request

The implementations of ReaderInterface have inconsistent behaviour.

  • Some (e.g., FileReader) will rely on the lower implementation to return an error if the seek fails.
  • Some (e.g. BufferReader) will return an error if the seek is past the end, but they won't modify m_pos.
  • Some (e.g., NetworkReader) will return an error if the seek is past the end, and they will modify m_pos.
  • Each of the above returns different error codes.

These implementations should be updated to give consistent behaviour when seeking past the end of an input stream (as discussed in this PR).

Possible implementation

What we probably want for try_seek_from_begin implementations is to:

  • try to seek until pos
  • if that's past the end of the medium (file/buffer/etc.), m_pos should be updated to just past the last byte.
  • the method should return ErrorCode_EndOfFile.

The reason to update m_pos even though we get to pos is because for some implementations like FileReader, we can't easily check what the last byte is until we seek, and if we seek up to the end of the file, we may not be able to seek backwards to the original m_pos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant