Make std::io::Take<R> an instance of std::io::Seek when R:std::io::Seek
This would be particularly useful for reading file formats containing other formats. Examples include:
- OpenType font files, where CFF is an embedded format.
- GRIB (format used by weather forecast organisms), containing grayscale JPEG to describe values.
(and probably many others) In such cases, it would also be cool to have a "drain" method on std::io::Take, that would move the read cursor at the end of the Take.
How would this implementation behave when
SeekFrom::StartorSeekFrom::Endis passed?Steven Fackler at 2016-10-16 17:31:23
Well, for my particular use case, it would be most useful to see a "subfile", hence, if
lenis the length passed totake:takedoes aseek(SeekFrom::Current(0))to determine the current position at the momenttake(len)is called, let's call that positionoffset.- then
SeekFrom::Start(n)actually performs aSeekFrom::Start(offset+n)on the underlyingSeek. SeekFrom::End(n)doesSeekFrom::Start(offset + len + n)on the underlyingSeek.
Deleted user at 2016-10-16 17:52:32
I am not 100% sold on the proposed implementation, but I would be interested in seeing a well-tested PR for adding this impl. I agree that seeking within a "subfile" seems reasonable.
David Tolnay at 2017-11-18 07:16:32