So I have data compressed in php in this way:
$compressed = gzcompress($pairs, 9);
When I try to decompress obtained data with rust in this way:
let mut d = flate2::read::GzDecoder::new(compressed_pairs.as_bytes());
let mut s = String::new();
d.read_to_string(&mut s).unwrap();
println!("{}", s);
I get this error - thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: InvalidInput, error: "invalid gzip header" }',
As I read here gzcompress is similar to gzencode, but with different header. Is it possible to decode it in Rust?
I found out here a C library and I thought that I can connect it to my Rust code, but may be there are simpler solution?
Please read your documentation.
The PHP function you reference "compresses the given string using the ZLIB data format" (despite being called gzcompress
, but that's the PHP standard library for you, never trust any function names). But you're trying to decompress it gzip data, not zlib. The docs even say "This is not the same as gzip compression".
You probably therefore want to use a zlib decoder.