-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathindex.eyg
More file actions
92 lines (83 loc) · 2.33 KB
/
Copy pathindex.eyg
File metadata and controls
92 lines (83 loc) · 2.33 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
let list_helpers = @standard.list
let contains = list_helpers.contains
let reverse = list_helpers.reverse
let print_line = (line) -> {
perform Print(!string_append(line, "\n"))
}
let path_join = (before, after) -> {
!string_append(before, !string_append("/", after))
}
let list = ({root, ignore}) -> {
let dirs = [""]
!fix((self, dirs, found) -> { match !list_pop(dirs) {
Ok ({head, tail}) -> {
let path = path_join(root, head)
// let _ = perform Log(path)
match perform ReadDirectory(path) {
Ok(children) -> {
let {dirs, found} = !list_fold(children, {dirs: tail, found}, ({type, name}, {dirs, found}) -> {
// head is the current dir
//
let relative = match !equal("", head) {
True(_) -> { name }
False(_) -> { path_join(head, name) }
}
let found = [{type,path: relative}, ..found]
let dirs = match type {
Directory(_) -> {
match contains(ignore, name) {
True(_) -> { dirs }
False(_) -> { [relative,..dirs] }
}
}
File(_) -> { dirs }
}
{dirs, found}
})
self(dirs, found)
}
Error(_) -> { self(tail, found) }
}
}
Error (_) -> {reverse(found)}
}},dirs,[])
}
let list_files = ({root, ignore}) -> {
let found=!list_fold(list({root, ignore}), [], ({type, path}, acc) -> {
match type {
Directory(_) -> { acc }
File(_) -> { [path,..acc] }
}
})
reverse(found)
}
let read_range = ({path, offset, limit}) -> {
perform ReadFile({path, offset, limit})
}
let read = (path) -> {
let chunk = 65536
!fix((self, offset, acc) -> {
match perform ReadFile({path, offset, limit: chunk}) {
Ok(bytes) -> {
let len = !binary_size(bytes)
let combined = !binary_concat(acc, bytes)
match !int_compare(len, chunk) {
Lt(_) -> { Ok(combined) }
Eq(_) -> { self(!int_add(offset, len), combined) }
Gt(_) -> { self(!int_add(offset, len), combined) }
}
}
Error(reason) -> { Error(reason) }
}
})(0, !string_to_binary(""))
}
let write = ({path, contents}) -> {
perform WriteFile({path, contents})
}
{
list,
list_files,
read,
read_range,
write
}