def readdata(file, size):
    """read and return data from file

    file: file object with read(size) method
    size: read this many bytes
    returns: bytes object of data read
    raises: EOFError if end of file is encountered before all bytes are read
    """
    data = file.read(size)
    if len(data) < size:
        raise EOFError(
            f"Tried to read {size} bytes from file, but there were only {len(data)} "
            "bytes remaining"
        )
    return data