You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A call to write represents at most one attempt to write to any wrapped object. [...]
If an error is returned then no bytes in the buffer were written to this writer.
let written = buf.read(&mutself.curr_buf[self.index..])?;
self.index += written;
ifself.index >= self.curr_buf.len(){
let filter_type = filter(
self.filter,
self.adaptive_filter,
self.bpp,
&self.prev_buf,
&mutself.curr_buf,
);
self.writer.write_all(&[filter_type asu8])?;
self.writer.write_all(&self.curr_buf)?;
mem::swap(&mutself.prev_buf,&mutself.curr_buf);
self.index = 0;
}
First buf always makes it into self.curr_buf even if one of the write_all calls errors. Second two write_alls is at least two writes to the wrapped writer and one write might make it to the writer, but a second write might error.
The text was updated successfully, but these errors were encountered:
That seems partially right. The 'at most one write' is not a hard requirement and it's not entirely clear either. See in particular this issue: rust-lang/rust#56889.
However, I very much agree on the odd behavior of partial effect on error.
The changes to index could be reverted when the write call fails, which virtually also reverts the write to buf.
There could be a spare byte at the start where the filter_type can be written which would make it possible to do a single write call, even without using vector IO.
Using even one write_all is not a single write, as it internally loops! The type would have to keep state for the case where the previous scanline was already filtered but only partially written, and it needs to be flushed before allowing the continuation. However here we run into the same issue as referenced above as we can't reasonably return 0.
I don't think
StreamWriter
is actually astd::io::Write
because the docs forwrite
sayand looking at
write
...image-png/src/encoder.rs
Lines 460 to 476 in 26f8f8b
First
buf
always makes it intoself.curr_buf
even if one of thewrite_all
calls errors. Second twowrite_all
s is at least two writes to the wrapped writer and one write might make it to the writer, but a second write might error.The text was updated successfully, but these errors were encountered: