Function glib::file_get_contents
source · pub fn file_get_contents(filename: impl AsRef<Path>) -> Result<Slice<u8>, Error>
Expand description
Reads an entire file into allocated memory, with good error checking.
If the call was successful, it returns true
and sets contents
to the file
contents and length
to the length of the file contents in bytes. The string
stored in contents
will be nul-terminated, so for text files you can pass
None
for the length
argument. If the call was not successful, it returns
false
and sets error
. The error domain is G_FILE_ERROR
. Possible error
codes are those in the FileError
enumeration. In the error case,
contents
is set to None
and length
is set to zero.
filename
name of a file to read contents from, in the GLib file name encoding
Returns
true
on success, false
if an error occurred
contents
location to store an allocated string, use g_free()
to free
the returned string