Read exactly length bytes from file; raise EOFError if file ends sooner.

def xread(file, length):
    "Read exactly length bytes from file; raise EOFError if file ends sooner."
    data = file.read(length)
    if len(data) != length:
        raise EOFError
    return data