title: GZip stream compression with Delphi (optionally with tar)
body: <p>I am searching and searching since hours to create a valid .tar.gz file using streams in Delphi 10.</p>
  
  <p>I was able to solve the tarball part using <a href="http://www.destructor.de/" rel="nofollow noreferrer">LibTar</a>, which works well.</p>
  
  <p>After some searching I also found examples to decompress gzip data using just <code>System.ZLib</code>. The secret lies in the WindowBits parameter:</p>
  
  <pre class="lang-delphi prettyprint-override"><code>// 31 bit wide window = gzip only mode
  DecompStream:= TZDecompressionStream.Create(SourceStream, 15 + 16);
  TarStream:= TTarArchive.Create(DecompStream);
  TarStream.Reset;
  while TarStream.FindNext(DirRec) do {...} TarStream.ReadFile(TargetStream);
  </code></pre>
  
  <p>Great! But is it really possible that <code>System.ZLib</code> is able to decompress gzip (I guess by just ignoring the gzip header by that +16?), but is not able to create such header by itself? Whatever I try, I only get a file that cannot be opened by 7zip or WinRar, because the header is missing.</p>
  
  <p>Maybe it just can't work, because the gzip header contains a checksum, so it's not possible to write the header without knowing the following data. How to solve this? Edit: this is wrong, see comments: crc32 is in the trailer.</p>
  
  <p>It seems, many others also have this problem - I found and tried multiple solutions to add this header, but nothing really worked and everything requires adding long units (not nice but acceptable) or even DLLs (not acceptable for me). </p>