-
Notifications
You must be signed in to change notification settings - Fork 1
/
Fs.hx
136 lines (115 loc) · 2.78 KB
/
Fs.hx
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package why;
import haxe.DynamicAccess;
import tink.http.Method;
import tink.http.Header;
import tink.state.Progress;
using tink.CoreApi;
using tink.io.Sink;
using tink.io.Source;
interface Fs {
/**
* Download a file
* @param req -
* @param local - loca path
* @return Progress<Outcome<Noise, Error>>
*/
function download(req:RequestInfo, local:String):Progress<Outcome<Noise, Error>>;
/**
* List all files that starts with the path prefix.
* Returned values have the prefix stripped
* @param path -
* @return Promise<Array<String>>
*/
function list(path:String, ?recursive:Bool):Promise<Array<Entry>>;
/**
* Check if a file exists
* @param path -
* @return Promise<Bool>
*/
function exists(path:String):Promise<Bool>;
/**
* Move (rename) a file
* @param from -
* @param to -
* @return Promise<Noise>
*/
function move(from:String, to:String):Promise<Noise>;
/**
* Copy a file
* @param from -
* @param to -
* @return Promise<Noise>
*/
function copy(from:String, to:String):Promise<Noise>;
/**
* Create a read stream to the target file
* @param path -
* @return RealSource
*/
function read(path:String):RealSource;
/**
* Create a write stream to the target file
* @param path -
* @return RealSink
*/
function write(path:String, ?options:WriteOptions):RealSink;
/**
* Delete (recursively) all files with the path prefix
* @param path -
* @return Promise<Noise>
*/
function delete(path:String):Promise<Noise>;
/**
* Get the file information
* @param path -
* @return Promise<Stat>
*/
function stat(path:String):Promise<Stat>;
/**
* Create a URL that can be used to download the file
* @param path -
* @return Promise<String>
*/
function getDownloadUrl(path:String, ?options:DownloadOptions):Promise<RequestInfo>;
/**
* Create a URL that can be used to upload the file
* @param path -
* @return Promise<String>
*/
function getUploadUrl(path:String, ?options:UploadOptions):Promise<RequestInfo>;
}
typedef Stat = {
?size:Int,
?mime:String,
?lastModified:Date,
?metadata:DynamicAccess<String>,
}
typedef RequestInfo = {
method:Method,
url:String,
headers:Array<HeaderField>,
}
typedef WriteOptions = UploadOptions;
typedef DownloadOptions = {
?isPublic:Bool,
?saveAsFilename:String,
}
typedef UploadOptions = {
?mime:String,
?isPublic:Bool,
?cacheControl:String,
?expires:Date,
?metadata:DynamicAccess<String>,
}
enum EntryType {
File;
Directory;
}
@:forward
abstract Entry({path:String, type:EntryType, stat:Stat}) to {path:String, type:EntryType, stat:Stat} {
public inline function new(path, type, stat)
this = {path: path, type: type, stat: stat}
@:to
public inline function toString():String
return this.path;
}