def _GetChunkForWriting(self, chunk):
    try:
      chunk = self.chunk_cache.Get(chunk)
      chunk.dirty = True
      return chunk
    except KeyError:
      pass

    try:
      chunk = self._ReadChunk(chunk)
      chunk.dirty = True
      return chunk
    except KeyError:
      pass

    fd = StringIO.StringIO()
    fd.chunk = chunk
    fd.dirty = True
    self.chunk_cache.Put(chunk, fd)
    return fd
Opens a chunk for writing, creating a new one if it doesn't exist yet.
dataset/ETHPy150Open google/grr/grr/lib/aff4.py/AFF4ImageBase._GetChunkForWriting