lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Dec 1, 2020 at 10:05 PM Tom Sutcliffe wrote:
But short story is yes "rb" and "wb" are valid modes and probably the only modes you should ever use on Windows (unless you actually want magic line ending translation, which generally speaking is better done at a way higher level).

Both modes (text and binary) are equally important on WIndows.
Always-binary "rb"/"wb" approach is good only for regular files.
But when you read data from a named pipe or a COM-port, you have to use text reading mode.
This is because devices (unlike files) do not have an "end of file", and you can't successfully invoke file:read("*a") for a Windows device opened in binary mode.
So, you need to use EOF emulation: the sender appends the "\x1A" character to the data stream, and the receiver opens the device for reading in text mode.
The EOF emulation is the main reason for text mode to exist; LF/CRLF conversion is just a bonus.