'Delete the file from the archive. If it appears multiple
times only the first instance will be deleted.'

def delete(self, name):

    for i in range(0, len(self.filelist)):
        if (self.filelist[i].filename == name):
            if self.debug:
                print 'Removing', name
            deleted_offset = self.filelist[i].header_offset
            deleted_size = ((self.filelist[i].file_offset - self.filelist[i].header_offset) + self.filelist[i].compress_size)
            zinfo_size = ((struct.calcsize(structCentralDir) + len(self.filelist[i].filename)) + len(self.filelist[i].extra))
            current_offset = self.fp.tell()
            self.fp.seek(0, 2)
            archive_size = self.fp.tell()
            self.fp.seek((deleted_offset + deleted_size))
            buf = self.fp.read()
            self.fp.seek(deleted_offset)
            self.fp.write(buf)
            self.fp.truncate(((archive_size - deleted_size) - zinfo_size))
            if (current_offset > (deleted_offset + deleted_size)):
                current_offset -= deleted_size
            elif (current_offset > deleted_offset):
                current_offset = deleted_offset
            self.fp.seek(current_offset, 0)
            del self.filelist[i]
            for j in range(i, len(self.filelist)):
                if (self.filelist[j].header_offset > deleted_offset):
                    self.filelist[j].header_offset -= deleted_size
                if (self.filelist[j].file_offset > deleted_offset):
                    self.filelist[j].file_offset -= deleted_size
            self._didModify = True
            return
    if self.debug:
        print name, 'not    in    archive'
