lua-users home
lua-l archive

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

On Wed, Jul 15, 2020 at 11:25 AM Andrew Gierth
<> wrote:

> Wouldn't binary mode be almost always the wrong choice, though?

We are talking about Lua's "standard library" io.popen(), whose
official documentation says nothing about binary or text modes. The
documentation only mentions "r" and "w" as possible modes. So the
first choice is whether you want your users to refer just to the Lua
docs, or look elsewhere. It is a fairly straight-forward choice in my
opinion. Once you decide to go with the Lua docs, there is no way (for
the user) to choose a text/binary sub-mode. Then the choice (for you)
is whether the use of "r" or "w" yields consistent results across
invocations - i.e., whether it is always binary or always text, or
sometimes binary and sometimes text. I find this pretty
straight-forward to answer, too. Then your choice is between always
binary and always text. Always text means that there is always a lossy
transformation acting on the pipe, which, again, makes the choice

So, unless we see in the Lua docs on io.popen() a way to specify
binary or text modes, I'd say "binary" is the only really sensible

On a slightly different tangent, popen() originally is a POSIX API. In
POSIX, there are no "binary" or "text" stream modes; or, rather, every
stream - and pipe - is a "binary" mode. They explicitly say that "b"
in fopen() has no effect. So it is hard to see how "binary" would be
"almost always wrong", when there might just be nothing else.