create_readwrite_async


Description:

[ Version ( since = "2.22" ) ]
public virtual async FileIOStream create_readwrite_async (FileCreateFlags flags, int io_priority = DEFAULT, Cancellable? cancellable = null) throws Error

Asynchronously creates a new file and returns a stream for reading and writing to it.

The file must not already exist.

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

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

Example: Create a file, rw, async:

public static int main (string[] args) {
MainLoop loop = new MainLoop ();

// Create a file for reading and writing:
File file = File.new_for_path ("my-test.txt");
file.create_readwrite_async.begin (FileCreateFlags.PRIVATE, Priority.DEFAULT, null, (obj, res) => {;
try {
FileIOStream stream = file.create_readwrite_async.end (res);
stream.output_stream.write ("My first line\n".data);
} catch (Error e) {
print ("Error: %s\n", e.message);
}

loop.quit ();
});

loop.run ();
return 0;
}

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

Parameters:

this

input File

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