import io
import xdrlib


def read_xdr_file(filename):  # ,var,cl=None,verbose=False):
    """
    Reads data from XDR file.

    Because of the way xdrlib works, this reads the whole file to
    memory at once. Avoid with very large files.

    Parameters
    ----------
    filename : string
        File to read.

    Returns
    -------
    result   : xdrlib.Unpacker object
    """
    try:
        f = io.open(filename, 'rb')
        data = f.read()
        f.close()
    except IOError as e:
        raise IOError(
            'read_xdr_file: problem reading {0}: {1}'.format(filename, e))
    # return XDR data
    return xdrlib.Unpacker(data)