These functions complement readBin
and
writeBin
which read and write C-style zero-terminated
character strings. They are for strings of known length, and
can optionally write an end-of-string mark. They are intended only
for character strings valid in the current locale.
These functions are intended to be used with binary-mode connections.
If con
is a character string, the functions call
file
to obtain a binary-mode file connection which is
opened for the duration of the function call.
If the connection is open it is read/written from its current
position. If it is not open, it is opened for the duration of the
call in an appropriate mode (binary read or write) and then closed
again. An open connection must be in binary mode.
If readChar
is called with con
a raw vector, the data in
the vector is used as input. If writeChar
is called with
con
a raw vector, it is just an indication that a raw vector
should be returned.
Character strings containing ASCII nul
(s) will be read
correctly by readChar
but truncated at the first
nul
with a warning.
If the character length requested for readChar
is longer than
the data available on the connection, what is available is
returned. For writeChar
if too many characters are requested
the output is zero-padded, with a warning.
Missing strings are written as NA
.