while writing/reading of file in text mode, the new line character is translated in to carriage return and linefeed i.e \n to \r\n but in binary mode this doesn't happen.
Similarly, the ASCII value 26 will be written at the end of file in text mode but this doesn't happen in binary mode.
I know this question was asked earlier in SO but there i didn't find any reasoning for this behavior.
I mean, is this behavior is just to differentiate the text and binary mode or is there any specific reason of this translation and not writing ASCII value 26 in case of binary mode.
Text file handling is operating system dependent. Binary files are not processed at all. Windows, replaces line endings with CR+LF, and in Linux, and OSX it is LF. In Linux, there is no difference between text file and binary file processing when OS is concerned.
In a sense, binary mode is "raw": nothing is translated, since it has no basis for doing so. Whereas in text mode, the file is interpreted as text, and thus (for example) line endings get translated to the appropriate representation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With