def read_count(f, n):
    """Read n bytes from a file stream; return empty string on EOF"""
    buf = ''
    while len(buf) < n:
        nextchunk = f.read(n - len(buf))
        if not nextchunk:
            return ''
        buf += nextchunk
    return buf