Re: GIOChannel missing binary mode?



> From: Michael Natterer <mitch gimp org>
>
> Hi,
>
> while porting GIMP <-> plug-in communication to
> g_io_channel_[read|write]_chars() i noticed that there
> are two GIOChannel attributes, "do_encode" and "encoding".
>
> My impression from looking at the code is that if
> "do_encode" == FALSE, "encoding" is assumed to be UTF-8.

Actually, it's assumed to be either "UTF-8" or NULL. Use
NULL for binary encoding. The default just happens to
be "UTF-8".

> So either I missed something or there seems to be no way
> to use a GIOChannel in binary mode, because if I say
> g_io_channel_set_encoding (channel, NULL, NULL),
> "do_encoding" is set to FALSE automatically.

The do_encode flag is set when we are calling g_iconv to do conversion.
It just happens this is true for neither UTF-8 or binary encoding.

> A subsequent call to read_chars() or write_chars() however
> looks at "do_encode", assumes UTF-8 if it is FALSE and
> calls g_utf8_validate() which of course fails on binary
> data.

In write_chars(), a binary encoding hits the earlier !channel->encoding
test and completely avoids checking do_encode. In read_chars(),
the test for binary encoding is hidden in the USE_BUF() macro.


> Please point me to the right direction if I made a mistake :-)
>
> (FYI: right now, as a workaround, i use channel->funcs->io_foo())

Just call g_io_channel_set_encoding() with a NULL argument before
you use the channel. If this isn't in the docs, it should be.

Ron Steinke




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