'Read the buffer and write to the file.'

@flow.StateHandler()
def ReadBuffer(self, responses):

    if responses.success:
        response = responses.First()
        if (not response):
            raise IOError(('Missing    hash    for    offset    %s    missing' % response.offset))
        if (response.offset <= (self.state.max_chunk_number * self.CHUNK_SIZE)):
            self.state.blobs.append((response.data, response.length))
            self.Log('Received    blob    hash    %s', response.data.encode('hex'))
            self.FetchWindow(1)
        if ((response.offset + response.length) >= self.state.file_size):
            stat_entry = self.state.stat_entry
            urn = self.state.stat_entry.AFF4Path(self.client_id)
            with aff4.FACTORY.Create(urn, aff4_grr.VFSBlobImage, token=self.token) as fd:
                fd.SetChunksize(self.CHUNK_SIZE)
                fd.Set(fd.Schema.STAT(stat_entry))
                for (data, length) in self.state.blobs:
                    fd.AddBlob(data, length)
                    fd.Set(fd.Schema.CONTENT_LAST, rdfvalue.RDFDatetime.Now())
                del self.state.blobs
            self.state.success = True
