import io


def bufferize(f, buf):
    """Bufferize a fileobject using buf."""
    if buf is None:
        return f
    else:
        if (buf.__name__ == io.BufferedWriter.__name__ or
                buf.__name__ == io.BufferedReader.__name__):
            return buf(f, buffer_size=10 * 1024 ** 2)
        return buf(f)