GflsLoaderBasic

## GflsLoaderBasic GflsLoaderBasic — Basic file loader |

## Functions

void | gfls_loader_basic_load_async ()
GBytes * | gfls_loader_basic_load_finish ()

## Types and Values

#define | GFLS_LOADER_ERROR
enum | GflsLoaderError

## Object Hierarchy

        GEnum
        ╰── GflsLoaderError

## Includes

    #include <gfls/gfls.h>

## Description

Basic file loader that validates input for GtkTextView purposes:

- Must not exceed a certain size (because all the content of a GtkTextBuffer is stored in memory).

- Must be valid UTF-8 already (GTK in general accepts only UTF-8 only strings).

- Must not contain very long lines (not well supported by the GtkTextView widget, there can be performance problems and freezes).

So:

- No character encoding auto-detection and/or conversion.

- No workarounds for problems found, just return an error without the possibility to re-configure the loading.

But this basic file loader offers a convenient API for the above: GFile loading with the intention to put its content into a GtkTextBuffer.

## Functions

### gfls_loader_basic_load_async ()

    void
    gfls_loader_basic_load_async (GFile *file,
                                  gsize max_size,
                                  guint max_n_bytes_per_line,
                                  gint io_priority,
                                  GCancellable *cancellable,
                                  GAsyncReadyCallback callback,
                                  gpointer user_data);

Starts a basic file loading operation.

If the `file` content is not a valid UTF-8 string, or if the `max_size` or `max_n_bytes_per_line` conditions are not satisfied, an error will be returned without the file content.

See the GAsyncResult documentation to know how to use this function.

#### Parameters

file | a GFile. |
max_size | the maximum allowed number of bytes in total. |
max_n_bytes_per_line | the maximum allowed number of bytes per line, as per `gfls_utf8_has_very_long_line()`. |
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_loader_basic_load_finish ()

    GBytes *
    gfls_loader_basic_load_finish (GFile *file,
                                   GAsyncResult *result,
                                   GError **error);

Finishes an operation started with `gfls_loader_basic_load_async()`.

If everything went well, a GBytes with the GFile content (unmodified) is returned. It is guaranteed to be a valid UTF-8 string.

Otherwise an error is returned. The `GFLS_LOADER_ERROR` domain is used, among others.

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

file | a GFile. |
result | a GAsyncResult. |
error | a GError, or `NULL`. |

#### Returns

a GBytes, or `NULL` on error.

Since: 0.1

## Types and Values

### GFLS_LOADER_ERROR

    #define GFLS_LOADER_ERROR gfls_loader_error_quark ()

### enum GflsLoaderError

An error code used with the `GFLS_LOADER_ERROR` domain.

#### Members

GFLS_LOADER_ERROR_TOO_BIG | The content is too big. |
GFLS_LOADER_ERROR_NOT_UTF8 | The content is not a valid UTF-8 string. Used by basic loaders that don't support charset conversion. |
GFLS_LOADER_ERROR_HAS_VERY_LONG_LINE | The content contains a very long line. |

Since: 0.1