title: Compressing and decompressing a tar.gz file
body: <p>I'm trying to compress a directory into a <code>tar.gz</code> file and decompressing it after using Rust.
  I'm using the crates <code>tar = &quot;0.4.35&quot;</code> and <code>flate2 = &quot;1.0.20&quot;</code>. I'm on Windows.</p>
  <p>My code is almost identical to the examples <a href="https://rust-lang-nursery.github.io/rust-cookbook/compression/tar.html#decompress-a-tarball-while-removing-a-prefix-from-the-paths" rel="nofollow noreferrer">here</a>.</p>
  <pre><code>let tar = File::create(&quot;a.tar.gz&quot;).unwrap();
  let enc = GzEncoder::new(tar, Compression::default());
  let mut a = tar::Builder::new(enc);
  a.append_dir_all(&quot;&quot;, &quot;in&quot;).unwrap();
  </code></pre>
  <pre><code>let tar = File::open(&quot;a.tar.gz&quot;).unwrap();
  let dec = GzDecoder::new(tar);
  let mut a = Archive::new(dec);
  a.unpack(&quot;out&quot;).unwrap();
  </code></pre>
  <p>I'm always getting an error when decompressing:
  <code>thread 'main' panicked at 'called Result::unwrap() on an </code>Err<code>value: Custom { kind: InvalidInput, error: TarError { desc: &quot;failed to iterate over archive&quot;, io: Custom { kind: InvalidInput, error: &quot;invalid gzip header&quot; } } }', src\main.rs:21:26</code></p>
  <p>I can open the generated <code>tar.gz</code> in 7-Zip without a problem.
  What am I doing wrong or is it an issue with the crates?</p>