Saving the stream to a string fixed the issue

It allows me to replace any problematic bits.