Description
You of course have already seen rust-lang/backtrace-rs#626 and I figured I'd capture some thoughts about the discussion there.
I won't try to persuade you that StreamingDecoder::read
should behave differently in the general case! But it would seem more natural, to me, for the Read::read_exact
case to have more of a "do what I mean" quality to it, even though this contradicts the documentation of StreamingDecoder
that says:
StreamingDecoder expects the underlying stream to only contain a single frame, yet the specification states that a single archive may contain multiple frames.
To decode all the frames in a finite stream, the calling code needs to recreate the instance of the decoder and handle crate::frame::ReadFrameHeaderError::SkipFrame errors by skipping forward the length amount of bytes, see #57
Personally, I tend to dislike read_exact
for the precise reason that it seems like a much more "magical" function to me than read
, as it says "Reads the exact number of bytes required to fill buf
. This function reads as many bytes as necessary to completely fill the specified buffer buf
." and is very prone to leaving the buffer and reader in unspecified states, considering:
If this function encounters an “end of file” before completely filling the buffer, it returns an error of the kind ErrorKind::UnexpectedEof. The contents of buf are unspecified in this case.
If any other read error is encountered then this function immediately returns. The contents of buf are unspecified in this case.
If this function returns an error, it is unspecified how many bytes it has read, but it will never read more than would be necessary to completely fill the buffer.
Naturally of course there could be another Decoder type that implements such semantics, but would it really differ, if you had your way, on more than this one function?