## GflsInputStream

GflsInputStream — Additional functions for GInputStream

## Functions

void | gfls_input_stream_read_async ()
GBytes * | gfls_input_stream_read_finish ()

## Includes

    #include <gfls/gfls.h>

## Description

Additional functions for GInputStream.

## Functions

### gfls_input_stream_read_async ()

    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.

#### Parameters

input_stream | a GInputStream. |
expected_size | the expected number of bytes contained in `input_stream` . |
max_size | the maximum number of bytes to read. |
io_priority | the I/O priority of the request. E.g. `G_PRIORITY_LOW`, `G_PRIORITY_DEFAULT` or `G_PRIORITY_HIGH`. |
cancellable | optional GCancellable object, `NULL` to ignore. | [nullable]
callback | a GAsyncReadyCallback to call when the operation is finished. | [scope async]
user_data | user data to pass to `callback` . |

Since: 0.1

### gfls_input_stream_read_finish ()

    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.

#### Parameters

input_stream | a GInputStream. |
result | a GAsyncResult. |
is_truncated | will be set to `TRUE` if the `input_stream` contains more data to be read, but the maximum number of bytes to read has been reached. |
error | a GError, or `NULL`. |

#### Returns

a GBytes, or `NULL` on error.

Since: 0.1