Resource
Added in version 2.32.
- class Resource(*args, **kwargs)
- Constructors:
new_from_data(data:GLib.Bytes) -> Gio.Resource
Constructors
- class Resource
- classmethod new_from_data(data: Bytes) 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
_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,INTERNAL
will be returned.Added in version 2.32.
- Parameters:
data – A
Bytes
Methods
- class Resource
- enumerate_children(path: str, lookup_flags: ResourceLookupFlags) list[str]
Returns all the names of children at the specified
path
in the resource. The return result is aNone
terminated list of strings which should be released withstrfreev()
.If
path
is invalid or does not exist in theResource
,NOT_FOUND
will be returned.lookup_flags
controls the behaviour of the lookup.Added in version 2.32.
- Parameters:
path – A pathname inside the resource
lookup_flags – A
ResourceLookupFlags
- get_info(path: str, lookup_flags: 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.Added in version 2.32.
- Parameters:
path – A pathname inside the resource
lookup_flags – A
ResourceLookupFlags
- load(filename: str) Resource
Loads a binary resource bundle and creates a
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
_register()
.If
filename
is empty or the data in it is corrupt,INTERNAL
will be returned. Iffilename
doesn’t exist, or there is an error in reading it, an error fromnew()
will be returned.Added in version 2.32.
- Parameters:
filename – the path of a filename to load, in the GLib filename encoding
- lookup_data(path: str, lookup_flags: ResourceLookupFlags) Bytes
Looks for a file at the specified
path
in the resource and returns aBytes
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.Added in version 2.32.
- Parameters:
path – A pathname inside the resource
lookup_flags – A
ResourceLookupFlags
- open_stream(path: str, lookup_flags: ResourceLookupFlags) InputStream
Looks for a file at the specified
path
in the resource and returns aInputStream
that lets you read the data.lookup_flags
controls the behaviour of the lookup.Added in version 2.32.
- Parameters:
path – A pathname inside the resource
lookup_flags – A
ResourceLookupFlags