Flate2 ZlibDecoder returning empty slice

โš“ Rust    ๐Ÿ“… 2026-01-30    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 8      

surdeus

Warning

This post was published 32 days ago. The information described in this article may have changed.

Hi 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

Read full topic

๐Ÿท๏ธ Rust_feed