This should work with both LF or CR-LF line endings:
LF
CR-LF
sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' file