Skip to content

Commit 2c06191

Browse files
committed
Replace unsafe unwrap() in DeflateEncoder::finish with io::Result error
The `DeflateEncoder::finish` method used `.unwrap()` on an `Option` returned by `self.writer.take()`. This change replaces it with `.ok_or_else()`, returning a descriptive `std::io::Error` instead. This prevents potential panics and improves the overall robustness of the streaming API.
1 parent 97a5bfd commit 2c06191

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/stream.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ impl<W: Write + Send> DeflateEncoder<W> {
199199
/// but will silently ignore any errors.
200200
pub fn finish(mut self) -> io::Result<W> {
201201
self.flush_buffer(true)?;
202-
Ok(self.writer.take().unwrap())
202+
self.writer
203+
.take()
204+
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "encoder already finished"))
203205
}
204206
}
205207

0 commit comments

Comments
 (0)