Merge #13159: Replace FileIO's quadratic-time buffer growth algorithm with a linear-time one.

Also fix the bz2 module, which suffered from the same problem.