:right-sidebar: True Resource =================================================================== .. currentmodule:: gi.repository.Gio .. versionadded:: 2.32 .. class:: Resource(*args, **kwargs) :no-contents-entry: :Constructors: :: new_from_data(data:GLib.Bytes) -> Gio.Resource Constructors ------------ .. rst-class:: interim-class .. class:: Resource :no-index: .. classmethod:: new_from_data(data: ~gi.repository.GLib.Bytes) -> ~gi.repository.Gio.Resource Creates a GResource from a reference to the binary resource bundle. This will keep a reference to ``data`` while the resource lives, so the data should not be modified or freed. If you want to use this resource in the global resource namespace you need to register it with :func:`~gi.repository.Gio.Resource._register`. Note: ``data`` must be backed by memory that is at least pointer aligned. Otherwise this function will internally create a copy of the memory since GLib 2.56, or in older versions fail and exit the process. If ``data`` is empty or corrupt, :const:`~gi.repository.Gio.ResourceError.INTERNAL` will be returned. .. versionadded:: 2.32 :param data: A :obj:`~gi.repository.GLib.Bytes` Methods ------- .. rst-class:: interim-class .. class:: Resource :no-index: .. method:: enumerate_children(path: str, lookup_flags: ~gi.repository.Gio.ResourceLookupFlags) -> list[str] Returns all the names of children at the specified ``path`` in the resource. The return result is a :const:`None` terminated list of strings which should be released with :func:`~gi.repository.GLib.strfreev`. If ``path`` is invalid or does not exist in the :obj:`~gi.repository.Gio.Resource`, :const:`~gi.repository.Gio.ResourceError.NOT_FOUND` will be returned. ``lookup_flags`` controls the behaviour of the lookup. .. versionadded:: 2.32 :param path: A pathname inside the resource :param lookup_flags: A :obj:`~gi.repository.Gio.ResourceLookupFlags` .. method:: get_info(path: str, lookup_flags: ~gi.repository.Gio.ResourceLookupFlags) -> tuple[bool, int, int] Looks for a file at the specified ``path`` in the resource and if found returns information about it. ``lookup_flags`` controls the behaviour of the lookup. .. versionadded:: 2.32 :param path: A pathname inside the resource :param lookup_flags: A :obj:`~gi.repository.Gio.ResourceLookupFlags` .. method:: load(filename: str) -> ~gi.repository.Gio.Resource Loads a binary resource bundle and creates a :obj:`~gi.repository.Gio.Resource` representation of it, allowing you to query it for data. If you want to use this resource in the global resource namespace you need to register it with :func:`~gi.repository.Gio.Resource._register`. If ``filename`` is empty or the data in it is corrupt, :const:`~gi.repository.Gio.ResourceError.INTERNAL` will be returned. If ``filename`` doesn’t exist, or there is an error in reading it, an error from :func:`~gi.repository.GLib.MappedFile.new` will be returned. .. versionadded:: 2.32 :param filename: the path of a filename to load, in the GLib filename encoding .. method:: lookup_data(path: str, lookup_flags: ~gi.repository.Gio.ResourceLookupFlags) -> ~gi.repository.GLib.Bytes Looks for a file at the specified ``path`` in the resource and returns a :obj:`~gi.repository.GLib.Bytes` that lets you directly access the data in memory. The data is always followed by a zero byte, so you can safely use the data as a C string. However, that byte is not included in the size of the GBytes. For uncompressed resource files this is a pointer directly into the resource bundle, which is typically in some readonly data section in the program binary. For compressed files we allocate memory on the heap and automatically uncompress the data. ``lookup_flags`` controls the behaviour of the lookup. .. versionadded:: 2.32 :param path: A pathname inside the resource :param lookup_flags: A :obj:`~gi.repository.Gio.ResourceLookupFlags` .. method:: open_stream(path: str, lookup_flags: ~gi.repository.Gio.ResourceLookupFlags) -> ~gi.repository.Gio.InputStream Looks for a file at the specified ``path`` in the resource and returns a :obj:`~gi.repository.Gio.InputStream` that lets you read the data. ``lookup_flags`` controls the behaviour of the lookup. .. versionadded:: 2.32 :param path: A pathname inside the resource :param lookup_flags: A :obj:`~gi.repository.Gio.ResourceLookupFlags`