| Top |
void gfls_input_stream_read_async (GInputStream *input_stream,gsize expected_size,gsize max_size,gint io_priority,GCancellable *cancellable,GAsyncReadyCallback callback,gpointer user_data);
This function starts a read operation on input_stream
. It is meant to be
used as the only read operation on input_stream
, to get a GBytes as a
result, with max_size
as the provided maximum number of bytes to read.
expected_size
is typically a GFile size as returned by
g_file_info_get_size(). But note that in that case, the returned GBytes may
contain a different number of bytes than what was expected (the
TOC/TOU problem: time of check to time of use). expected_size
is used as an
indication to how much memory to allocate initially.
See the GAsyncResult documentation to know how to use this function.
input_stream |
a GInputStream. |
|
expected_size |
the expected number of bytes contained in |
|
max_size |
the maximum number of bytes to read. |
|
io_priority |
the I/O priority of the request. E.g. |
|
cancellable |
optional GCancellable object, |
[nullable] |
callback |
a GAsyncReadyCallback to call when the operation is finished. |
[scope async] |
user_data |
user data to pass to |
Since: 0.1
GBytes * gfls_input_stream_read_finish (GInputStream *input_stream,GAsyncResult *result,gboolean *is_truncated,GError **error);
Finishes an operation started with gfls_input_stream_read_async().
If is_truncated
is set to TRUE, it is not an error (error
is not set), and
a GBytes is returned. However, since gfls_input_stream_read_async() is meant
to be used as the only read operation on input_stream
, it is an undefined
behavior if you try to read more content from input_stream
.
The data contained in the resulting GBytes is always zero-terminated, but
this is not included in the GBytes length. The resulting GBytes should be
freed with g_bytes_unref() when no longer in use.
input_stream |
a GInputStream. |
|
result |
a GAsyncResult. |
|
is_truncated |
will be set to |
|
error |
a GError, or |
Since: 0.1