title: Multi-part gzip file random access (in Java)
body: <p>This may fall in the realm of "not really feasible" or "not really worth the effort" but here goes.</p>
  
  <p>I'm trying to randomly access records stored inside a multi-part gzip file. Specifically, the files I'm interested in are compressed <a href="http://crawler.archive.org/" rel="noreferrer">Heretrix</a> Arc files. (In case you aren't familiar with multi-part gzip files, the gzip spec allows multiple gzip streams to be concatenated in a single gzip file. They do not share any dictionary information, it is simple binary appending.)</p>
  
  <p>I'm thinking it should be possible to do this by seeking to a certain offset within the file, then scan for the gzip magic header bytes (i.e. 0x1f8b, as per the <a href="http://www.ietf.org/rfc/rfc1952.txt" rel="noreferrer">RFC</a>), and attempt to read the gzip stream from the following bytes. The problem with this approach is that those same bytes can appear inside the actual data as well, so seeking for those bytes can lead to an invalid position to start reading a gzip stream from. Is there a better way to handle random access, given that the record offsets aren't known a priori?</p>