Provides some I/O-related utilities complimenting
std::fs. I split these more general utilities out of recent work on body-image. Includes:
GatheringReader presents a continuous
Read interface over N non-contiguous byte buffers, and is used for the scattered
Ram variant of
BodyImage. This is more efficient than the current implementation of
std::io::Cursor::chain for many reads over many buffers. See the associated benchmark comparison.
ReadSlice types support multiple independent instance positions over a shared
File reference, without needing a path to open an independent new
File instance. Thus they are compatible with “unnamed” (not linked) temporary files (tempfile @stebalien) , and can reduce the number of necessary file handles. Note that unix
dup2 and the standard
File::try_clone do not provide independent file positions.
I couldn’t find anything comparable to
GatheringReader, but after an initial prototype, I did find and considered using the positioned-io crate for the latter. This crate has broader application including positioned writes and much more flexibility. However, I couldn’t quite achieve what I needed with positioned-io—a
Read-only slice-type facade using a shared (
Arc<File>) reference (
If @vasi was interested to comment here or on github at the possibility of extending positioned-io for these use-case variants, I’m potentially interested in contributing this and some more time to adapt it.