import bz2
import pickle


def read_pickle(filepath, compressed=False):
    """ Reads the summarized background from a compressed binary file

    Parameters
    ----------
    filepath:
        Filepath to compressed file
    compressed:
        Whether to use bz2 compression. Defaults to False
    """
    if compressed:
        with bz2.BZ2File(filepath, 'rb') as f:
            data = pickle.load(f)
    else:
        with open(filepath, 'rb') as f:
            data = pickle.load(f)
    
    return data