TeplFileLoader: Tepl 4 Reference Manual

## TeplFileLoader TeplFileLoader — Load a file into a TeplBuffer |

## Functions

TeplFileLoader * | tepl_file_loader_new ()
TeplBuffer * | tepl_file_loader_get_buffer ()
TeplFile * | tepl_file_loader_get_file ()
GFile * | tepl_file_loader_get_location ()
gint64 | tepl_file_loader_get_max_size ()
void | tepl_file_loader_set_max_size ()
gint64 | tepl_file_loader_get_chunk_size ()
void | tepl_file_loader_set_chunk_size ()
void | tepl_file_loader_load_async ()
gboolean | tepl_file_loader_load_finish ()
const TeplEncoding * | tepl_file_loader_get_encoding ()
TeplNewlineType | tepl_file_loader_get_newline_type ()

## Properties

TeplBuffer * | buffer | Read / Write / Construct Only
gint64 | chunk-size | Read / Write / Construct
TeplFile * | file | Read / Write / Construct Only
GFile * | location | Read / Write / Construct Only
gint64 | max-size | Read / Write / Construct

## Types and Values

| TeplFileLoader
#define | TEPL_FILE_LOADER_ERROR
enum | TeplFileLoaderError

## Object Hierarchy

        GEnum
        ╰── TeplFileLoaderError
        GObject
        ╰── TeplFileLoader

## Includes

    #include <tepl/tepl.h>

## Description

TeplFileLoader is not a fork of GtkSourceFileLoader, it is a new implementation based on uchardet.

A TeplFileLoader object permits to load the content of a GFile into a TeplBuffer.

A file loader should be used only for one load operation, including errors handling. If an error occurs, you can reconfigure the loader and relaunch the operation with `tepl_file_loader_load_async()`.

Running a TeplFileLoader is an undoable action for the TeplBuffer. That is, `gtk_source_buffer_begin_not_undoable_action()` and `gtk_source_buffer_end_not_undoable_action()` are called, which delete the undo/redo history.

After a file loading, the buffer is reset to the content provided by the GFile, so the buffer is set as “unmodified”, that is, `gtk_text_buffer_set_modified()` is called with `FALSE`.

## Functions

### tepl_file_loader_new ()

    TeplFileLoader *
    tepl_file_loader_new (TeplBuffer *buffer,
                          TeplFile *file);

Creates a new TeplFileLoader object. The content is read from the TeplFile location.

If not already done, call `tepl_file_set_location()` before calling this constructor. The previous location is anyway not needed, because as soon as the file loading begins, the `buffer` is emptied. Setting the TeplFile location directly permits to update the UI, to display the good location when the file is loading.

#### Parameters

buffer | the TeplBuffer to load the content into. |
file | the TeplFile. |

#### Returns

a new TeplFileLoader object.

Since: 1.0

### tepl_file_loader_get_buffer ()

    TeplBuffer *
    tepl_file_loader_get_buffer (TeplFileLoader *loader);

#### Parameters

loader | a TeplFileLoader. |

#### Returns

the TeplBuffer to load the content into.

[transfer none][nullable]

Since: 1.0

### tepl_file_loader_get_file ()

    TeplFile *
    tepl_file_loader_get_file (TeplFileLoader *loader);

#### Parameters

loader | a TeplFileLoader. |

#### Returns

the TeplFile.

[transfer none][nullable]

Since: 1.0

### tepl_file_loader_get_location ()

    GFile *
    tepl_file_loader_get_location (TeplFileLoader *loader);

#### Parameters

loader | a TeplFileLoader. |

#### Returns

the GFile to load.

[transfer none][nullable]

Since: 1.0

### tepl_file_loader_get_max_size ()

    gint64
    tepl_file_loader_get_max_size (TeplFileLoader *loader);

#### Parameters

loader | a TeplFileLoader. |

#### Returns

the maximum content size, or -1 for unlimited.

Since: 1.0

### tepl_file_loader_set_max_size ()

    void
    tepl_file_loader_set_max_size (TeplFileLoader *loader,
                                   gint64 max_size);

#### Parameters

loader | a TeplFileLoader. |
max_size | the new maximum size, or -1 for unlimited. |

Since: 1.0

### tepl_file_loader_get_chunk_size ()

    gint64
    tepl_file_loader_get_chunk_size (TeplFileLoader *loader);

#### Parameters

loader | a TeplFileLoader. |

#### Returns

the chunk size.

Since: 1.0

### tepl_file_loader_set_chunk_size ()

    void
    tepl_file_loader_set_chunk_size (TeplFileLoader *loader,
                                     gint64 chunk_size);

#### Parameters

loader | a TeplFileLoader. |
chunk_size | the new chunk size. |

Since: 1.0

### tepl_file_loader_load_async ()

    void
    tepl_file_loader_load_async (TeplFileLoader *loader,
                                 gint io_priority,
                                 GCancellable *cancellable,
                                 GFileProgressCallback progress_callback,
                                 gpointer progress_callback_data,
                                 GDestroyNotify progress_callback_notify,
                                 GAsyncReadyCallback callback,
                                 gpointer user_data);

Loads asynchronously the file content into the TeplBuffer.

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

#### Parameters

loader | a TeplFileLoader. |
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]
progress_callback | function to call back with progress information, or `NULL` if progress information is not needed. | [scope notified][nullable]
progress_callback_data | user data to pass to `progress_callback` . | [closure]
progress_callback_notify | function to call on `progress_callback_data` when the `progress_callback` is no longer needed, or `NULL`. | [nullable]
callback | a GAsyncReadyCallback to call when the request is satisfied. | [scope async]
user_data | user data to pass to `callback` . |

Since: 1.0

### tepl_file_loader_load_finish ()

    gboolean
    tepl_file_loader_load_finish (TeplFileLoader *loader,
                                  GAsyncResult *result,
                                  GError **error);

Finishes a file loading started with `tepl_file_loader_load_async()`.

#### Parameters

loader | a TeplFileLoader. |
result | a GAsyncResult. |
error | a GError, or `NULL`. |

#### Returns

whether the content has been loaded successfully.

Since: 1.0

### tepl_file_loader_get_encoding ()

    const TeplEncoding *
    tepl_file_loader_get_encoding (TeplFileLoader *loader);

#### Parameters

loader | a TeplFileLoader. |

#### Returns

the detected file encoding, or `NULL`.

[nullable]

Since: 2.0

### tepl_file_loader_get_newline_type ()

    TeplNewlineType
    tepl_file_loader_get_newline_type (TeplFileLoader *loader);

#### Parameters

loader | a TeplFileLoader. |

#### Returns

the detected newline type.

Since: 2.0

## Types and Values

### TeplFileLoader

    typedef struct _TeplFileLoader TeplFileLoader;

### TEPL_FILE_LOADER_ERROR

    #define TEPL_FILE_LOADER_ERROR tepl_file_loader_error_quark ()

### enum TeplFileLoaderError

An error code used with the `TEPL_FILE_LOADER_ERROR` domain.

#### Members

TEPL_FILE_LOADER_ERROR_TOO_BIG | The file is too big. |
TEPL_FILE_LOADER_ERROR_ENCODING_AUTO_DETECTION_FAILED | It is not possible to detect the encoding automatically. |

Since: 1.0

## Property Details

### The `“buffer”` property

      “buffer”                   TeplBuffer *

The TeplBuffer to load the content into. The TeplFileLoader object has a weak reference to the buffer.

Owner: TeplFileLoader

Flags: Read / Write / Construct Only

Since: 1.0

### The `“chunk-size”` property

      “chunk-size”               gint64

The chunk size, in bytes. The content is loaded chunk by chunk. It permits to avoid allocating a too big contiguous memory area, as well as reporting progress information after each chunk read.

A small chunk size is better when loading a remote file with a slow connection. For local files, the chunk size can be larger.

Owner: TeplFileLoader

Flags: Read / Write / Construct

Allowed values: >= 1

Default value: 8192

Since: 1.0

### The `“file”` property

      “file”                     TeplFile *

The TeplFile. The TeplFileLoader object has a weak reference to the file.

Owner: TeplFileLoader

Flags: Read / Write / Construct Only

Since: 1.0

### The `“location”` property

      “location”                 GFile *

The GFile to load. By default the location is taken from the TeplFile at construction time.

Owner: TeplFileLoader

Flags: Read / Write / Construct Only

Since: 1.0

### The `“max-size”` property

      “max-size”                 gint64

The maximum content size, in bytes. Keep in mind that all the content is loaded in memory, and when loaded into a GtkTextBuffer it takes more memory than just the content size.

Set to -1 for unlimited size.

Owner: TeplFileLoader

Flags: Read / Write / Construct

Allowed values: >= -1

Default value: 50000000

Since: 1.0

## See Also

TeplFile, TeplFileSaver