load_contents


Description:

public bool load_contents (Cancellable? cancellable, out uint8[] contents, out string? etag_out) throws Error

Loads the content of the file into memory.

The data is always zero-terminated, but this is not included in the resultant contents.length. The returned contents should be freed with g_free when no longer needed.

If cancellable is not null, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error g_io_error_cancelled will be returned.

Example: Load content, sync:

public static int main (string[] args) {
if (args.length != 2) {
print ("%s FILE\n", args[0]);
return 0;
}

try {
uint8[] contents;
string etag_out;

File file = File.new_for_commandline_arg (args[1]);
file.load_contents (null, out contents, out etag_out);

print ("%s", (string) contents);
} catch (Error e) {
print ("Error: %s\n", e.message);
}

return 0;
}

valac --pkg gio-2.0 GLib.File.load_contents.vala

Parameters:

this

input File

cancellable

optional Cancellable object, null to ignore

contents

a location to place the contents of the file

etag_out

a location to place the current entity tag for the file, or null if the entity tag is not needed

length

a location to place the length of the contents of the file, or null if the length is not needed

Returns:

true if the this's contents were successfully loaded. false if there were errors.