public IOStatus set_encoding (string? encoding) throws IOChannelError

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 null 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 null or UTF-8.
  • One of the (new API) read functions has just returned g_io_status_eof (or, in the case of read_to_end, g_io_status_normal).
  • One of the functions read_chars or read_unichar has returned g_io_status_again or g_io_status_error. This may be useful in the case of g_convert_error_illegal_sequence. Returning one of these statuses from read_line, read_line_string, 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 an offset of g_seek_cur, and, if they are "seekable", cannot call write_chars after calling one of the API "read" functions.



a IOChannel


the encoding type


g_io_status_normal if the encoding was successfully set