-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfs.echo
More file actions
96 lines (89 loc) · 1.39 KB
/
Copy pathfs.echo
File metadata and controls
96 lines (89 loc) · 1.39 KB
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
; Filesystem: paths, whole-file, metadata, streaming, dirs.
; Run: xo run examples/misc/fs.echo
/ std/io
/ std/str
/ std/bytes
/ std/fs
$ root = fs.join("/tmp", "echo_fs_example")
| fs.create_dir_all(root) {
$ ok {
io.print("dir ok")
}
! e {
io.print(e)
}
}
$ path = fs.join(root, "note.txt")
| fs.create(path) {
$ f {
| f.write("hello") {
$ ok {
io.print("stream write")
}
! e {
io.print(e)
}
}
f.close()
}
! e {
io.print(e)
}
}
$ copy = fs.join(root, "copy.txt")
| fs.copy(path, copy) {
$ ok {
io.print("copied")
}
! e {
io.print(e)
}
}
| fs.metadata(path) {
$ m {
io.print(str.from_int(m.len))
}
! e {
io.print(e)
}
}
| fs.open(path) {
$ f {
| f.read(100) {
$ b {
io.print(str.from_bytes(b))
}
! e {
io.print(e)
}
}
f.close()
}
! e {
io.print(e)
}
}
| fs.remove(path) {
$ ok {
io.print("rm file")
}
! e {
io.print(e)
}
}
| fs.remove(copy) {
$ ok {
io.print("rm copy")
}
! e {
io.print(e)
}
}
| fs.remove_dir(root) {
$ ok {
io.print("rm dir")
}
! e {
io.print(e)
}
}