ogg icon indicating copy to clipboard operation
ogg copied to clipboard

Allow usage without `Seek`: `RevReader` approach

Open florian1345 opened this issue 2 years ago • 0 comments

Implemented my proposal to resolve #12 .

Instead of Seek, the (non-seeking) functionality of the PacketReader now requires a new trait RevRead which allows making a single reversible read operation. This is blanket-implemented for all types implementing Read + Seek, so business as usual is possible. Beyond that, I added the RevReader which implements RevRead solely on the basis of Read. This allows usage of the PacketReader with underlying readers that do not implement Seek.

The tests seem to pass (on my machine), but I have not yet tried to apply this to an OGG file where seeking is actually necessary. Do the tests cover that scenario?

Potential Drawbacks

  • The interface of some public functions has changed.
  • Currently, the RevRead trait carries an annoying lifetime that is required to return references to internal state of the reader. This could probably be resolved with generic associated types (https://github.com/rust-lang/rust/issues/44265).
  • Potentially slightly slower performance with general reads when using the RevReader. I have not run any benchmarks yet, if that is necessary, please request.

florian1345 avatar Aug 02 '22 19:08 florian1345