optimize formatter.py, no need to buffer all data