'Write the hash received to the blob image.'

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

    index = responses.request_data['index']
    if (index not in self.state.pending_files):
        return
    if (not responses.success):
        self._FileFetchFailed(index, responses.request.request.name)
        return
    response = responses.First()
    file_tracker = self.state.pending_files.get(index)
    if file_tracker:
        file_tracker.setdefault('blobs', []).append((response.data, response.length))
        download_size = file_tracker['size_to_download']
        if ((response.length < self.CHUNK_SIZE) or ((response.offset + response.length) >= download_size)):
            stat_entry = file_tracker['stat_entry']
            urn = stat_entry.pathspec.AFF4Path(self.client_id)
            with aff4.FACTORY.Create(urn, aff4_grr.VFSBlobImage, mode='w', token=self.token) as fd:
                fd.SetChunksize(self.CHUNK_SIZE)
                fd.Set(fd.Schema.STAT(stat_entry))
                fd.Set(fd.Schema.PATHSPEC(stat_entry.pathspec))
                fd.Set(fd.Schema.CONTENT_LAST(rdfvalue.RDFDatetime().Now()))
                for (digest, length) in file_tracker['blobs']:
                    fd.AddBlob(digest, length)
                del file_tracker['blobs']
            self._ReceiveFetchedFile(file_tracker)
            self.Publish('FileStore.AddFileToStore', urn, priority=rdf_flows.GrrMessage.Priority.LOW_PRIORITY)
            self.state.files_fetched += 1
            if (not (self.state.files_fetched % 100)):
                self.Log('Fetched    %d    of    %d    files.', self.state.files_fetched, self.state.files_to_fetch)
