Make std::io::Take<R> an instance of std::io::Seek when R:std::io::Seek

181679a
Opened by Deleted user at 2023-09-24 16:33:52

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.

  1. How would this implementation behave when SeekFrom::Start or SeekFrom::End is passed?

    Steven Fackler at 2016-10-16 17:31:23

  2. Well, for my particular use case, it would be most useful to see a "subfile", hence, if len is the length passed to take:

    • take does a seek(SeekFrom::Current(0)) to determine the current position at the moment take(len) is called, let's call that position offset.
    • then SeekFrom::Start(n) actually performs a SeekFrom::Start(offset+n) on the underlying Seek.
    • SeekFrom::End(n) does SeekFrom::Start(offset + len + n) on the underlying Seek.

    Deleted user at 2016-10-16 17:52:32

  3. 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