-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.go
104 lines (97 loc) · 2.25 KB
/
io.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package fs
import (
"os"
)
// Notes:
// Why do we provide those wrappers?
// We provide wrappers for built-in functions for two primary reasons:
// 1. To provide a standard interface for common operations, making
// it easier for developers to understand and investigate the code.
// 2. (not yet) The SDK, if used to create a new VOS App instance, will
// be able to log all the application's operations in the system log,
// making it easier to debug and monitor the application by both the
// developer and the system administrator.
// CopyFile copies the contents of one file to another
//
// Example:
//
// err := fs.CopyFile("/tmp/batman", "/tmp/robin")
// if err != nil {
// fmt.Printf("Error copying file: %v", err)
// return
// }
func CopyFile(sourcePath, destinationPath string) error {
source, err := os.ReadFile(sourcePath)
if err != nil {
return err
}
err = os.WriteFile(destinationPath, source, 0644)
if err != nil {
return err
}
return nil
}
// MoveFile moves a file from one location to another
//
// Example:
//
// err := fs.MoveFile("/tmp/batman", "/tmp/robin")
// if err != nil {
// fmt.Printf("Error moving file: %v", err)
// return
// }
func MoveFile(sourcePath, destinationPath string) error {
err := os.Rename(sourcePath, destinationPath)
if err != nil {
return err
}
return nil
}
// DeleteFile deletes a file
//
// Example:
//
// err := fs.DeleteFile("/tmp/batman")
// if err != nil {
// fmt.Printf("Error deleting file: %v", err)
// return
// }
func DeleteFile(filePath string) error {
err := os.Remove(filePath)
if err != nil {
return err
}
return nil
}
// CreateDirectory creates a new directory
//
// Example:
//
// err := fs.CreateDirectory("/tmp/batman")
// if err != nil {
// fmt.Printf("Error creating directory: %v", err)
// return
// }
func CreateDirectory(directoryPath string) error {
err := os.Mkdir(directoryPath, 0755)
if err != nil {
return err
}
return nil
}
// DeleteDirectory deletes a directory and its contents
//
// Example:
//
// err := fs.DeleteDirectory("/tmp/batman")
// if err != nil {
// fmt.Printf("Error deleting directory: %v", err)
// return
// }
func DeleteDirectory(directoryPath string) error {
err := os.RemoveAll(directoryPath)
if err != nil {
return err
}
return nil
}