-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.go
70 lines (60 loc) · 2.09 KB
/
fs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package gokio
import (
"github.com/myyrakle/gost"
)
// Creates a new, empty directory at the provided path
func CreateDir(path gost.String) gost.Future[gost.Result[any]] {
return Spawn(func() gost.Result[any] {
return gost.CreateDir(path)
})
}
// Removes an empty directory.
func RemoveDir(path gost.String) gost.Future[gost.Result[any]] {
return Spawn(func() gost.Result[any] {
return gost.RemoveDir(path)
})
}
// Write a slice as the entire contents of a file.
func Write(path gost.String, data []gost.Byte) gost.Future[gost.Result[any]] {
return Spawn(func() gost.Result[any] {
return gost.Write(path, data)
})
}
// Removes a file from the filesystem.
func RemoveFile(path gost.String) gost.Future[gost.Result[any]] {
return Spawn(func() gost.Result[any] {
return gost.RemoveFile(path)
})
}
// Rename a file or directory to a new name, replacing the original file if to already exists.
// This will not work if the new name is on a different mount point.
func Rename(from gost.String, to gost.String) gost.Future[gost.Result[any]] {
return Spawn(func() gost.Result[any] {
return gost.Rename(from, to)
})
}
// Read the entire contents of a file into a bytes vector.
func Read(path gost.String) gost.Future[gost.Result[[]gost.Byte]] {
return Spawn(func() gost.Result[[]gost.Byte] {
return gost.Read(path)
})
}
// Returns an iterator over the entries within a directory.
func ReadDir(path gost.String) gost.Future[gost.Result[gost.Vec[gost.DirEntry]]] {
return Spawn(func() gost.Result[gost.Vec[gost.DirEntry]] {
return gost.ReadDir(path)
})
}
// Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file.
// This function will overwrite the contents of to.
func Copy(from gost.String, to gost.String) gost.Future[gost.Result[any]] {
return Spawn(func() gost.Result[any] {
return gost.Copy(from, to)
})
}
// Read the entire contents of a file into a string.
func ReadToString(path gost.String) gost.Future[gost.Result[gost.String]] {
return Spawn(func() gost.Result[gost.String] {
return gost.ReadToString(path)
})
}