Error while decoding just encoded data
Julian-Alberts opened this issue · comments
Julian Alberts commented
While testing my code, I encountered an issue where encoded data could not be decoded.
The following example panics with the message "called Result::unwrap()
on an Err
value: Error { kind: UnexpectedEof, message: "failed to fill whole buffer" }" at the last unwarp.
let mut encoded = Vec::new();
libflate::gzip::Encoder::new(&mut encoded)
.unwrap()
.write_all(b"Hello World")
.unwrap();
assert!(encoded.len() > 0);
let mut decoded = Vec::default();
libflate::gzip::Decoder::new(encoded.as_slice())
.unwrap()
.read_to_end(&mut decoded)
.unwrap();
assert_eq!(decoded.as_slice(), b"Hello World")
libflate version 1.3.0
rust version 1.68.0
Takeru Ohta commented
You need to call Encoder::finish()
as follows:
let mut encoded = Vec::new();
let mut encoder = libflate::gzip::Encoder::new(&mut encoded).unwrap();
encoder.write_all(b"Hello World").unwrap();
encoder.finish().unwrap();
assert!(encoded.len() > 0);
let mut decoded = Vec::default();
libflate::gzip::Decoder::new(encoded.as_slice())
.unwrap()
.read_to_end(&mut decoded)
.unwrap();
assert_eq!(decoded.as_slice(), b"Hello World")
Julian Alberts commented
Thanks, I don't know how I missed this.