title: Working on a Compressed File in Stages
body: <p>Okay so I have a cache file for a script of mine which is basically just a list of file-paths, but I like to keep it gzipped as it can otherwise get pretty huge.</p>
  
  <p>However, within my script I need to read it line-by-line, however I'm currently doing this by simply decompressing the whole file into <code>/tmp</code> and reading it from there using a file-descriptor (via <code>exec</code>) so I can <code>read</code> from it each time I need the next entry.</p>
  
  <p>Anyway, I wanted to know if there is a more efficient way that I could be doing this; I know how to read a file line by line by piping the output of <code>gzip</code> into a loop, however I only read lines from the cache file periodically, i.e - I'm already looping from a different set of data so I can't read from the cache that way too.</p>
  
  <p>Is there any way that I can read the contents of a gzipped file directly in a line-by-line way (doesn't need to use <code>read</code>) without having to expand it fully first, and without using a loop? If possible I'd appreciate an example of how to write a file in the same way, for when I need to create/update the cache file.</p>