`std::io::Chain` equivalent for `Read+Seek` instances

Essentially what the title says - since Read + Seek is such a common combination for parsers and other similar programs why isn't there a version of Read's std::io::Chain specific for Read + Seek?

In theory, we could just provide a Seek implementation for Chain if the chained readers provide Seek. The thing is that it's not immediately obvious how to actually do so; the behavior of seeking outside the stream is implementation defined, and getting the size of the stream(s) to determine how to translate the seek takes multiple seek operations.

There's also no actual requirement that Read+Seek presents a consistent size, so transparently precaching stream sizes wouldn't be correct either.

So in short: it'd be possible, but what exactly it means to chain two arbitrary Read+Seek isn't clear, let alone how the expected implementation should behave with translating seek requests. Just cursor-relative seeks are fairly clear, but absolute seeks are also provided by Seek and aren't obvious.

2 Likes

That makes sense considering variable stream lengths - thank you for the answer!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.