You're thinking of 'puts' which appends a newline.

'print' does not

The code does handle/preserve all the cases you mentioned (\r\n, final or no final terminating newline, etc).