GNOME Bugzilla – Bug 540459
there are no way of getting the real number of bytes written in GMemoryOutputStream
Last modified: 2008-06-30 03:07:33 UTC
http://library.gnome.org/devel/gio/stable/GMemoryOutputStream.html#g-memory-output-stream-get-size says that I could achieve with g_seekable_seek() and g_seekable_tell() to get the number of bytes written in GMemoryOutputStream. but what I can get with g_seekable_tell() is the number of bytes allocated, not written. $ cat t.c #include <gio/gio.h> int main(void) { GOutputStream *mo; GDataOutputStream *o; int i; GError *error = NULL; g_type_init(); mo = g_memory_output_stream_new(NULL, 0, g_realloc, g_free); o = g_data_output_stream_new(mo); g_data_output_stream_put_byte(o, 1, NULL, NULL); g_seekable_seek(G_SEEKABLE (mo), 0, G_SEEK_END, NULL, NULL); g_print("%d\n", g_seekable_tell(G_SEEKABLE (mo))); g_object_unref(o); g_object_unref(mo); return 0; } $ gcc t.c `pkg-config --cflags --libs gio-2.0` $ ./a.out 16
The docs should say G_SEEK_CUR, not G_SEEK_END. I've fixed the doc comment in the 2.16 branch