summaryrefslogtreecommitdiff
path: root/lib/astal/io/file.vala
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-10-16 12:47:38 +0200
committerGitHub <[email protected]>2024-10-16 12:47:38 +0200
commitc012b5699afd401942e1044c204fb6a666d0a094 (patch)
tree5cd27e5162a84f2ee5310fc698d7b50ee08eddf0 /lib/astal/io/file.vala
parent2ad95e05d83a455bb30503ca4ca0aa8356ea5ff7 (diff)
parent8368b20eda96674e0f5a502b92d3afb936b71b0b (diff)
Merge branch 'main' into fix/fuzzy-search
Diffstat (limited to 'lib/astal/io/file.vala')
-rw-r--r--lib/astal/io/file.vala17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/astal/io/file.vala b/lib/astal/io/file.vala
index b2d480c..e57f449 100644
--- a/lib/astal/io/file.vala
+++ b/lib/astal/io/file.vala
@@ -1,4 +1,7 @@
namespace AstalIO {
+/**
+ * Read the contents of a file synchronously.
+ */
public string read_file(string path) {
var str = "";
try {
@@ -9,12 +12,18 @@ public string read_file(string path) {
return str;
}
+/**
+ * Read the contents of a file asynchronously.
+ */
public async string read_file_async(string path) throws Error {
uint8[] content;
yield File.new_for_path(path).load_contents_async(null, out content, null);
return (string)content;
}
+/**
+ * Write content to a file synchronously.
+ */
public void write_file(string path, string content) {
try {
FileUtils.set_contents(path, content);
@@ -23,6 +32,9 @@ public void write_file(string path, string content) {
}
}
+/**
+ * Write content to a file asynchronously.
+ */
public async void write_file_async(string path, string content) throws Error {
yield File.new_for_path(path).replace_contents_async(
content.data,
@@ -33,6 +45,11 @@ public async void write_file_async(string path, string content) throws Error {
null);
}
+/**
+ * Monitor a file for changes. If the path is a directory, monitor it recursively.
+ * The callback will be called passed two parameters: the path of the file
+ * that changed and an [[email protected]] indicating the reason.
+ */
public FileMonitor? monitor_file(string path, Closure callback) {
try {
var file = File.new_for_path(path);