Flate2 ZlibDecoder returning empty slice
โ Rust ๐ 2026-01-30 ๐ค surdeus ๐๏ธ 8Hi everyone
I cannot seem to get ZlibDecoder to decompress my data. It is giving me an empty slice.
Here is the code
use std::io::Read;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let buf = &std::fs::read("img.dat")?[..];
let mut z = flate2::read::ZlibDecoder::new(buf);
let mut inflated = Vec::<u8>::new();
let x = z.read(&mut inflated)?;
println!("z.read returned: {}", x);
println!("inflated len: {}", inflated.len());
Ok(())
}
When I run it, 0 is printed twice.
In Cargo.toml is:
[dependencies]
flate2 = "1.1.8"
Here is a gist of the file (base64 encoded) img.dat.b64 ยท GitHub
The first bytes are 78 9c which should indicate zlib compressed data. Python's zlib library and OpenSSL (from the command line) both correctly decompress it (when decompressed it should have length 3000 * 1841 * 3 = 16569000)
Apologies if there's something obvious I've missed, and thanks in advance.
3 posts - 2 participants
๐ท๏ธ Rust_feed