file: add g_file_load_bytes()

This adds g_file_load_bytes() to make it more convenient to
load the contents of a GFile as GBytes.

It includes a special casing for gresources to increase the
chances that the GBytes directly references the embedded data
instead of copying to the heap.

https://bugzilla.gnome.org/show_bug.cgi?id=790272
This commit is contained in:
Christian Hergert
2017-11-12 19:55:52 -08:00
parent 5464461e4c
commit 2227918dfd
3 changed files with 207 additions and 0 deletions

View File

@@ -1251,6 +1251,22 @@ gboolean g_file_replace_contents_finish (GFile *file,
GLIB_AVAILABLE_IN_ALL
gboolean g_file_supports_thread_contexts (GFile *file);
GLIB_AVAILABLE_IN_2_56
GBytes *g_file_load_bytes (GFile *file,
GCancellable *cancellable,
gchar **etag_out,
GError **error);
GLIB_AVAILABLE_IN_2_56
void g_file_load_bytes_async (GFile *file,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GLIB_AVAILABLE_IN_2_56
GBytes *g_file_load_bytes_finish (GFile *file,
GAsyncResult *result,
gchar **etag_out,
GError **error);
G_END_DECLS
#endif /* __G_FILE_H__ */