Fixing migration errors: stream.read() doesn't read the entire available stream. It has to be called in a loop or replaced with readFully().