title: is partial gz decompression possible?
body: <p>For working with images that are stored as .gz files (my image processing software can read .gz files for shorter/smaller disk time/space) I need to check the header of each file. </p>
  
  <p>The header is just a small struct of a fixed size at the start of each image, and for images that are not compressed, checking it is very fast. For reading the compressed images, I have no choice but to decompress the whole file and then check this header, which of course slows down my program.</p>
  
  <p>Would it be possible to read the first segment of a .gz file (say a couple of K), decompress this segment and read the original contents? My understanding of gz is that after some bookkeeping at the start, the compressed data is stored sequentially -- is that correct?</p>
  
  <p>so instead of<br>
  1. open big file <code>F</code><br>
  2. decompress big file <code>F</code><br>
  3. read 500-byte header<br>
  4. re-compress big file <code>F</code><br></p>
  
  <p>do<br>
  1. open big file <code>F</code><br>
  2. read first 5 K from <code>F</code> as stream <code>A</code><br>
  3. decompress <code>A</code> as stream <code>B</code><br>
  4. read 500-byte header from <code>B</code><br></p>
  
  <p>I am using <code>libz.so</code> but solutions in other languages are appreciated!</p>