title: How to write multiple protocol buffers' messages into an a appendable compressed file?
body: <p>I'm using protocol buffers' CodedOutputStream and FileOutputStream to serialize multiple messages in sequence into a file like this:</p>
  
  <pre><code>// File is opened using append mode and wrapped into
  // a FileOutputStream and a CodedOutputStream
  bool Open(const std::string&amp; filename,
            int buffer_size = kDefaultBufferSize) {
  
      file_ = open(filename.c_str(),
                   O_WRONLY | O_APPEND | O_CREAT, // open mode
                   S_IREAD | S_IWRITE | S_IRGRP | S_IROTH | S_ISUID); //file permissions
  
      if (file_ != -1) {
          file_ostream_ = new FileOutputStream(file_, buffer_size);
          ostream_ = new CodedOutputStream(file_ostream_);
          return true;
      } else {
          return false;
      }
  }
  
  // Code for append a new message
  bool Serialize(const google::protobuf::Message&amp; message) {
      ostream_-&gt;WriteLittleEndian32(message.ByteSize());
      return message.SerializeToCodedStream(ostream_);
  }
  
  // Code for reading a message using a FileInputStream
  // wrapped into a CodedInputStream 
  bool Next(google::protobuf::Message *msg) {
      google::protobuf::uint32 size;
      bool has_next = istream_-&gt;ReadLittleEndian32(&amp;size);
      if(!has_next) {
          return false;
      } else {
          CodedInputStream::Limit msgLimit = istream_-&gt;PushLimit(size);
          if ( msg-&gt;ParseFromCodedStream(istream_) ) {
              istream_-&gt;PopLimit(msgLimit);
              return true;
          }
          return false;
      }
  }
  </code></pre>
  
  <p>How can I do the same using a GzipOutputStream? Can a gzip compressed file be reopened to append new messages like I do using CodedOutputStream?</p>