GNOME Bugzilla – Bug 679668
gio: g_input_stream_read_bytes() reads all bytes
Last modified: 2012-07-11 09:41:56 UTC
Currently using g_input_stream_read_bytes() is pretty strange because you need to be prepared to call it multiple times in order to get the data that you're expecting. In the end you can have N GBytes that you can't easily join or use together. So this changes it so we try to get the number of bytes requested and g_input_stream_read_bytes() becomes more like g_input_stream_read_all(). We could also change @count to be gssize, and if set to -1 try to read until EOF. This would be similar to python's fd.read() when no size is specified. What do you think?
Created attachment 218402 [details] [review] gio: g_input_stream_read_bytes() reads all bytes * Make g_input_stream_read_bytes() and friends behave more like g_input_stream_read_all(). Read all bytes requested until error or EOF. * These functions become much less awkward to use with GBytes, especially since you can't join bytes together, and generally shouldn't try to write to the data inside a GBytes.
Review of attachment 218402 [details] [review]: We don't have tests for this one? Code looks fine. ::: gio/ginputstream.c @@ +684,3 @@ + gsize nread; + int io_priority; +} ReadBytesClosure; Looking forward to GTask landing... @@ +691,3 @@ + ReadBytesClosure *closure = data; + if (closure->cancellable) + g_object_unref (closure->cancellable); g_clear_object() ?
Comment on attachment 218402 [details] [review] gio: g_input_stream_read_bytes() reads all bytes same bindings API issue as the write_bytes patch
Lets discuss this on at bug #679662. Would be nice if there was symmetry between the two solutions. *** This bug has been marked as a duplicate of bug 679662 ***