Functions

finalize ()

init ()

input_stream_read_async (input_stream, expected_size, max_size, io_priority, cancellable, callback, *user_data)

input_stream_read_finish (input_stream, result, is_truncated)

loader_basic_load_async (file, max_size, max_n_bytes_per_line, io_priority, cancellable, callback, *user_data)

loader_basic_load_finish (file, result)

loader_error_quark ()

utf8_find_very_long_line (str, max_n_bytes_per_line)

Details

Gfls.finalize()

Free the resources allocated by Gfls. For example it unrefs the singleton objects.

It is not mandatory to call this function, it’s just to be friendlier to memory debugging tools. This function is meant to be called at the end of main(). It can be called several times.

New in version 0.1.

Gfls.init()

Initializes the Gfls library (e.g. for the internationalization).

This function can be called several times, but is meant to be called at the beginning of main(), before any other Gfls function call.

New in version 0.1.

Gfls.input_stream_read_async(input_stream, expected_size, max_size, io_priority, cancellable, callback, *user_data)
Parameters:

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 GLib.Bytes as a result, with max_size as the provided maximum number of bytes to read.

expected_size is typically a Gio.File size as returned by Gio.FileInfo.get_size(). But note that in that case, the returned GLib.Bytes 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 Gio.AsyncResult documentation to know how to use this function.

New in version 0.1.

Gfls.input_stream_read_finish(input_stream, result, is_truncated)
Parameters:
Raises:

GLib.Error

Returns:

a GLib.Bytes, or None on error.

Return type:

GLib.Bytes

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 GLib.Bytes 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 GLib.Bytes is always zero-terminated, but this is not included in the GLib.Bytes length. The resulting GLib.Bytes should be freed with GLib.Bytes.unref() when no longer in use.

New in version 0.1.

Gfls.loader_basic_load_async(file, max_size, max_n_bytes_per_line, io_priority, cancellable, callback, *user_data)
Parameters:

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 Gio.AsyncResult documentation to know how to use this function.

New in version 0.1.

Gfls.loader_basic_load_finish(file, result)
Parameters:
Raises:

GLib.Error

Returns:

a GLib.Bytes, or None on error.

Return type:

GLib.Bytes

Finishes an operation started with Gfls.loader_basic_load_async().

If everything went well, a GLib.Bytes with the Gio.File 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 GLib.Bytes is always zero-terminated, but this is not included in the GLib.Bytes length. The resulting GLib.Bytes should be freed with GLib.Bytes.unref() when no longer in use.

New in version 0.1.

Gfls.loader_error_quark()
Return type:

int

Gfls.utf8_find_very_long_line(str, max_n_bytes_per_line)
Parameters:
  • str (str) – a UTF-8 nul-terminated string.

  • max_n_bytes_per_line (int) – the maximum number of bytes per line, without counting the newline character(s).

Returns:

a pointer to the beginning of the first very long line found, or None if not found.

Return type:

str

Finds if a line in str exceeds max_n_bytes_per_line.

For performance reasons, str is not checked whether it is a valid UTF-8 string. So you must call for example GLib.utf8_validate() beforehand.

New in version 0.3.