Sets the encoding for the input/output of the channel. The internal encoding is always UTF-8. The default encoding for the external file is UTF-8. The encoding
"" is safe to use with binary data.
The encoding can only be set if one of the following conditions is true:
- The channel was just created, and has not been written to or read from yet.
- The channel is write-only.
- The channel is a file, and the file pointer was just repositioned by a call to seek_position(). (This flushes all the internal buffers.)
- The current encoding is
"" or UTF-8.
- One of the read methods has just returned Glib::IO_STATUS_EOF (or, in the case of read_to_end(), Glib::IO_STATUS_NORMAL).
- The read() method has returned Glib::IO_STATUS_AGAIN or thrown a Glib::Error exception. This may be useful in the case of ConvertError::ILLEGAL_SEQUENCE. Returning one of these statuses from read_line() or read_to_end() does not guarantee that the encoding can be changed.
Channels which do not meet one of the above conditions cannot call seek_position() with a seek type of Glib::SEEK_TYPE_CUR and, if they are "seekable", cannot call write() after calling one of the API "read" methods.
|encoding ||The encoding name, or |
"" for binary.
- Glib::IO_STATUS_NORMAL if the encoding was successfully set.
Definition at line 272 of file iochannel.cc.
GError* error = 0;
const GIOStatus status = g_io_channel_set_encoding(
gobj(), (encoding.empty()) ? 0 : encoding.c_str(), &error);
return (IOStatus) status;