replace_async


Description:

public virtual async FileOutputStream replace_async (string? etag, bool make_backup, FileCreateFlags flags, int io_priority = DEFAULT, Cancellable? cancellable = null) throws Error

Asynchronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.

For more details, see replace which is the synchronous version of this call.

When the operation is finished, callback will be called. You can then call replace_async.end to get the result of the operation.

Example: Replace file-content (stream-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_async.begin (null, false, FileCreateFlags.NONE, Priority.DEFAULT, null, (obj, res) => {
try {
OutputStream ostream = file.replace_async.end (res);
DataOutputStream dostream = new DataOutputStream (ostream);
dostream.put_string ("new-line\n");
} catch (Error e) {
print ("Error: %s\n", e.message);
}

loop.quit ();
});

loop.run ();
return 0;
}

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

Parameters:

this

input File

etag

an entity tag for the current File, or null to ignore

make_backup

true if a backup should be created

flags

a set of FileCreateFlags

io_priority

the I/O priority of the request

cancellable

optional Cancellable object, null to ignore

callback

a TaskReadyCallback to call when the request is satisfied

user_data

the data to pass to callback function




2022 vala-language.org