## Storage of text sessions on the file system

Storage of text sessions on the file system — Utility functions to deal with storing InfTextSessions in filesystem storage

## Stability Level

Unstable, unless otherwise indicated

## Functions

gboolean | inf_text_filesystem_format_read ()
gboolean | inf_text_filesystem_format_write ()

## Types and Values

enum | InfTextFilesystemFormatError

## Includes

    #include <libinftext/inf-text-filesystem-storage.h>

## Description

The functions in this section are utility functions that can be used when implementing a InfdNotePlugin to handle InfTextSessions. These functions implement reading and writing the content of an InfTextSession to an XML file in the storage.

## Functions

### inf_text_filesystem_format_read ()

    gboolean
    inf_text_filesystem_format_read (InfdFilesystemStorage *storage,
                                     const gchar *path,
                                     InfUserTable *user_table,
                                     InfTextBuffer *buffer,
                                     GError **error);

Reads a text session from `path` in `storage` . The file is expected to have been saved with `inf_text_filesystem_format_write()` before. The `user_table` parameter should be an empty user table that will be used for the session, and the `buffer` parameter should be an empty InfTextBuffer, and the document will be written into this buffer. If the function succeeds, the user table and buffer can be used to create an InfTextSession with `inf_text_session_new_with_user_table()`. If the function fails, `FALSE` is returned and `error` is set.

#### Parameters

storage | A InfdFilesystemStorage. |
path | Storage path to retrieve the session from. |
user_table | An empty InfUserTable to use as the new session's user table. |
buffer | An empty InfTextBuffer to use as the new session's buffer. |
error | Location to store error information, if any, or `NULL`. |

#### Returns

`TRUE` on success or `FALSE` on error.

### inf_text_filesystem_format_write ()

    gboolean
    inf_text_filesystem_format_write (InfdFilesystemStorage *storage,
                                      const gchar *path,
                                      InfUserTable *user_table,
                                      InfTextBuffer *buffer,
                                      GError **error);

Writes the given user table and buffer into the filesystem storage at `path` . If successful, the session can then be read back with `inf_text_filesystem_format_read()`. If the function fails, `FALSE` is returned and `error` is set.

#### Parameters

storage | A InfdFilesystemStorage. |
path | Storage path where to write the session to. |
user_table | The InfUserTable to write. |
buffer | The InfTextBuffer to write. |
error | Location to store error information, if any, or `NULL`. |

#### Returns

`TRUE` on success or `FALSE` on error.

## Types and Values

### enum InfTextFilesystemFormatError

Errors that can occur when reading a InfTextSession from a InfdFilesystemStorage.

#### Members

INF_TEXT_FILESYSTEM_FORMAT_ERROR_NOT_A_TEXT_SESSION | The file to be read is not a serialized text session. |
INF_TEXT_FILESYSTEM_FORMAT_ERROR_USER_EXISTS | The user table of the session contains users with duplicate ID or duplicate name. |
INF_TEXT_FILESYSTEM_FORMAT_ERROR_NO_SUCH_USER | A segment of the text document is written by a user which does not exist. |

## See Also

InfTextSession, InfdFilesystemStorage