replace_contents_async


Description:

public async bool replace_contents_async (uint8[] contents, string? etag, bool make_backup, FileCreateFlags flags, Cancellable? cancellable = null, out string? new_etag) throws Error

Starts an asynchronous replacement of this with the given contents of contents.length bytes.

etag will replace the document's current entity tag.

When this operation has completed, callback will be called with user_user data, and the operation can be finalized with replace_contents_async.end.

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.

If make_backup is true, this function will attempt to make a backup of this.

Note that no copy of contents will be made, so it must stay valid until callback is called. See replace_contents_bytes_async for a Bytes version that will automatically hold a reference to the contents (without copying) for the duration of the call.

Example: Replace file-content (uint8[]-based), async:

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

MainLoop loop = new MainLoop ();

File file = File.new_for_commandline_arg (args[1]);
file.replace_contents_async.begin ("My info\n".data, null, false, FileCreateFlags.NONE, null, (obj, res) => {
try {
file.replace_contents_async.end (res, null);
} catch (Error e) {
print ("Error: %s\n", e.message);
}

loop.quit ();
});

loop.run ();
return 0;
}

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

Parameters:

this

input File

contents

string of contents to replace the file with

etag

a new [entity tag](entity-tags) for the this, or null

make_backup

true if a backup should be created

flags

a set of FileCreateFlags

cancellable

optional Cancellable object, null to ignore

callback

a TaskReadyCallback to call when the request is satisfied

length

the length of contents in bytes

user_data

the data to pass to callback function