Wrap the stream in TextIOWrapper with encoding='utf8' , then call .read(1) on it.
It is assumed that you started with BufferedIOBase or something like a duck type compatible with it (i.e. it has a read() method). If you have a generator or an iterator, you may need to adapt the interface.
Example:
from io import TextIOWrapper with open('/path/to/file', 'rb') as f: wf = TextIOWrapper(f, 'utf-8') wf._CHUNK_SIZE = 1
Kevin source share