Get the iterator over the sorted items.

        This function decides whether the items can be sorted in memory or on disk.
        :return:

def _get_sorted_iterator(self, iterator):
        """
        Get the iterator over the sorted items.

        This function decides whether the items can be sorted in memory or on disk.
        :return:
        """
        lines = list(next(iterator))
        if len(lines) < self.max_lines:
            return iter(sorted(lines, key=self.key))

        import tempfile
        tmp_dir = tempfile.mkdtemp()
        fnames = self._split(chain([lines], iterator), tmp_dir)
        return SortedIteratorMerger([unpickle_iter(open(fname, 'rb')) for fname in fnames], self.key)