@@ -24,9 +24,15 @@ module Node.FS.Aff
24
24
, exists
25
25
) where
26
26
27
- import Control.Monad.Eff (Eff (..))
27
+ import Node.Path (FilePath ())
28
+ import Node.FS.Perms (Perms ())
29
+ import Node.FS.Stats (Stats ())
30
+ import Data.Date (Date ())
31
+ import Control.Monad.Eff (Eff ())
28
32
import Data.Either (either )
29
- import Control.Monad.Aff (Aff (..), makeAff )
33
+ import Control.Monad.Aff (Aff (), makeAff )
34
+ import Node.Buffer (Buffer ())
35
+ import Node.Encoding (Encoding ())
30
36
import qualified Node.FS as F
31
37
import qualified Node.FS.Async as A
32
38
@@ -39,35 +45,187 @@ toAff1 f a = toAff (f a)
39
45
toAff2 f a b = toAff (f a b)
40
46
toAff3 f a b c = toAff (f a b c)
41
47
42
- rename = toAff2 A .rename
43
- truncate = toAff2 A .truncate
44
- chown = toAff3 A .chown
45
- chmod = toAff2 A .chmod
46
- stat = toAff1 A .stat
47
- link = toAff2 A .link
48
- symlink = toAff3 A .symlink
49
- readlink = toAff1 A .readlink
50
- realpath = toAff1 A .realpath
51
- realpath' = toAff2 A .realpath'
52
- unlink = toAff1 A .unlink
53
- rmdir = toAff1 A .rmdir
54
- mkdir = toAff1 A .mkdir
55
- mkdir' = toAff2 A .mkdir'
56
- readdir = toAff1 A .readdir
57
- utimes = toAff3 A .utimes
58
- readFile = toAff1 A .readFile
59
- readTextFile = toAff2 A .readTextFile
60
- writeFile = toAff2 A .writeFile
61
- writeTextFile = toAff3 A .writeTextFile
62
- appendFile = toAff2 A .appendFile
48
+ -- |
49
+ -- Renames a file.
50
+ --
51
+ rename :: forall eff . FilePath
52
+ -> FilePath
53
+ -> Aff (fs :: F.FS | eff ) Unit
54
+ rename = toAff2 A .rename
55
+
56
+ -- |
57
+ -- Truncates a file to the specified length.
58
+ --
59
+ truncate :: forall eff . FilePath
60
+ -> Number
61
+ -> Aff (fs :: F.FS | eff ) Unit
62
+ truncate = toAff2 A .truncate
63
+
64
+ -- |
65
+ -- Changes the ownership of a file.
66
+ --
67
+ chown :: forall eff . FilePath
68
+ -> Number
69
+ -> Number
70
+ -> Aff (fs :: F.FS | eff ) Unit
71
+ chown = toAff3 A .chown
72
+
73
+ -- |
74
+ -- Changes the permissions of a file.
75
+ --
76
+ chmod :: forall eff . FilePath
77
+ -> Perms
78
+ -> Aff (fs :: F.FS | eff ) Unit
79
+ chmod = toAff2 A .chmod
80
+
81
+ -- |
82
+ -- Gets file statistics.
83
+ --
84
+ stat :: forall eff . FilePath
85
+ -> Aff (fs :: F.FS | eff ) Stats
86
+ stat = toAff1 A .stat
87
+
88
+ -- |
89
+ -- Creates a link to an existing file.
90
+ --
91
+ link :: forall eff . FilePath
92
+ -> FilePath
93
+ -> Aff (fs :: F.FS | eff ) Unit
94
+ link = toAff2 A .link
95
+
96
+ -- |
97
+ -- Creates a symlink.
98
+ --
99
+ symlink :: forall eff . FilePath
100
+ -> FilePath
101
+ -> F.SymlinkType
102
+ -> Aff (fs :: F.FS | eff ) Unit
103
+ symlink = toAff3 A .symlink
104
+
105
+ -- |
106
+ -- Reads the value of a symlink.
107
+ --
108
+ readlink :: forall eff . FilePath
109
+ -> Aff (fs :: F.FS | eff ) FilePath
110
+ readlink = toAff1 A .readlink
111
+
112
+ -- |
113
+ -- Find the canonicalized absolute location for a path.
114
+ --
115
+ realpath :: forall eff . FilePath
116
+ -> Aff (fs :: F.FS | eff ) FilePath
117
+ realpath = toAff1 A .realpath
118
+
119
+ -- |
120
+ -- Find the canonicalized absolute location for a path using a cache object for
121
+ -- already resolved paths.
122
+ --
123
+ realpath' :: forall eff cache . FilePath
124
+ -> { | cache }
125
+ -> Aff (fs :: F.FS | eff ) FilePath
126
+ realpath' = toAff2 A .realpath'
127
+
128
+ -- |
129
+ -- Deletes a file.
130
+ --
131
+ unlink :: forall eff . FilePath
132
+ -> Aff (fs :: F.FS | eff ) Unit
133
+ unlink = toAff1 A .unlink
134
+
135
+ -- |
136
+ -- Deletes a directory.
137
+ --
138
+ rmdir :: forall eff . FilePath
139
+ -> Aff (fs :: F.FS | eff ) Unit
140
+ rmdir = toAff1 A .rmdir
141
+
142
+ -- |
143
+ -- Makes a new directory.
144
+ --
145
+ mkdir :: forall eff . FilePath
146
+ -> Aff (fs :: F.FS | eff ) Unit
147
+ mkdir = toAff1 A .mkdir
148
+
149
+ -- |
150
+ -- Makes a new directory with the specified permissions.
151
+ --
152
+ mkdir' :: forall eff . FilePath
153
+ -> Perms
154
+ -> Aff (fs :: F.FS | eff ) Unit
155
+ mkdir' = toAff2 A .mkdir'
156
+
157
+ -- |
158
+ -- Reads the contents of a directory.
159
+ --
160
+ readdir :: forall eff . FilePath
161
+ -> Aff (fs :: F.FS | eff ) [FilePath ]
162
+ readdir = toAff1 A .readdir
163
+
164
+ -- |
165
+ -- Sets the accessed and modified times for the specified file.
166
+ --
167
+ utimes :: forall eff . FilePath
168
+ -> Date
169
+ -> Date
170
+ -> Aff (fs :: F.FS | eff ) Unit
171
+ utimes = toAff3 A .utimes
172
+
173
+ -- |
174
+ -- Reads the entire contents of a file returning the result as a raw buffer.
175
+ --
176
+ readFile :: forall eff . FilePath
177
+ -> Aff (fs :: F.FS | eff ) Buffer
178
+ readFile = toAff1 A .readFile
179
+
180
+ -- |
181
+ -- Reads the entire contents of a text file with the specified encoding.
182
+ --
183
+ readTextFile :: forall eff . Encoding
184
+ -> FilePath
185
+ -> Aff (fs :: F.FS | eff ) String
186
+ readTextFile = toAff2 A .readTextFile
187
+
188
+ -- |
189
+ -- Writes a buffer to a file.
190
+ --
191
+ writeFile :: forall eff . FilePath
192
+ -> Buffer
193
+ -> Aff (fs :: F.FS | eff ) Unit
194
+ writeFile = toAff2 A .writeFile
195
+
196
+ -- |
197
+ -- Writes text to a file using the specified encoding.
198
+ --
199
+ writeTextFile :: forall eff . Encoding
200
+ -> FilePath
201
+ -> String
202
+ -> Aff (fs :: F.FS | eff ) Unit
203
+ writeTextFile = toAff3 A .writeTextFile
204
+
205
+ -- |
206
+ -- Appends the contents of a buffer to a file.
207
+ --
208
+ appendFile :: forall eff . FilePath
209
+ -> Buffer
210
+ -> Aff (fs :: F.FS | eff ) Unit
211
+ appendFile = toAff2 A .appendFile
212
+
213
+ -- |
214
+ -- Appends text to a file using the specified encoding.
215
+ --
216
+ appendTextFile :: forall eff . Encoding
217
+ -> FilePath
218
+ -> String
219
+ -> Aff (fs :: F.FS | eff ) Unit
63
220
appendTextFile = toAff3 A .appendTextFile
64
221
65
222
-- |
66
223
-- Patch `Node.FS.Async.exists`
67
224
--
68
225
import Data.Function
69
226
foreign import fs " var fs = require('fs');" ::
70
- { exists :: forall a . Fn2 String (Boolean -> a ) Unit }
227
+ { exists :: forall a . Fn2 FilePath (Boolean -> a ) Unit }
71
228
72
- exists :: forall e . String -> Aff (fs :: F.FS | e ) Boolean
229
+ exists :: forall eff . String
230
+ -> Aff (fs :: F.FS | eff ) Boolean
73
231
exists file = makeAff \_ a -> pure $ runFn2 fs.exists file a
0 commit comments