Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit c115a73

Browse files
committed
Add example and README
1 parent 6c021a0 commit c115a73

File tree

4 files changed

+345
-0
lines changed

4 files changed

+345
-0
lines changed

README.md

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
# Module Documentation
2+
3+
## Module Node.FS.Aff
4+
5+
6+
7+
[Node.FS][Node.FS] Wrappers for [purescript-aff][aff]
8+
9+
The `Aff` monad let's you write async code with ease.
10+
11+
Consider asynchronously listing only non-hidden directories:
12+
13+
``` purescript
14+
main = launchAff do
15+
files <- FS.readdir "."
16+
files' <- flip filterM files \file -> do
17+
stat <- FS.stat file
18+
return $
19+
FS.isDirectory stat
20+
&& (maybe false (fromChar >>> (/= ".")) $ charAt 0 file)
21+
liftEff $ Debug.Trace.trace $ show files'
22+
```
23+
24+
That was easy. For a working example, see [example.purs][example].
25+
To build the example, run `gulp example`.
26+
27+
[Node.FS]: http://github.com/purescript-node/purescript-node-fs
28+
[aff]: https://github.com/slamdata/purescript-aff
29+
[example]: http://github.com/purescript-node/purescript-node-fs-aff/blob/master/example/example.purs
30+
31+
#### `rename`
32+
33+
``` purescript
34+
rename :: forall eff. FilePath -> FilePath -> Aff (fs :: F.FS | eff) Unit
35+
```
36+
37+
38+
Rename a file.
39+
40+
41+
#### `truncate`
42+
43+
``` purescript
44+
truncate :: forall eff. FilePath -> Number -> Aff (fs :: F.FS | eff) Unit
45+
```
46+
47+
48+
Truncates a file to the specified length.
49+
50+
51+
#### `chown`
52+
53+
``` purescript
54+
chown :: forall eff. FilePath -> Number -> Number -> Aff (fs :: F.FS | eff) Unit
55+
```
56+
57+
58+
Changes the ownership of a file.
59+
60+
61+
#### `chmod`
62+
63+
``` purescript
64+
chmod :: forall eff. FilePath -> Perms -> Aff (fs :: F.FS | eff) Unit
65+
```
66+
67+
68+
Changes the permissions of a file.
69+
70+
71+
#### `stat`
72+
73+
``` purescript
74+
stat :: forall eff. FilePath -> Aff (fs :: F.FS | eff) Stats
75+
```
76+
77+
78+
Gets file statistics.
79+
80+
81+
#### `link`
82+
83+
``` purescript
84+
link :: forall eff. FilePath -> FilePath -> Aff (fs :: F.FS | eff) Unit
85+
```
86+
87+
88+
Creates a link to an existing file.
89+
90+
91+
#### `symlink`
92+
93+
``` purescript
94+
symlink :: forall eff. FilePath -> FilePath -> F.SymlinkType -> Aff (fs :: F.FS | eff) Unit
95+
```
96+
97+
98+
Creates a symlink.
99+
100+
101+
#### `readlink`
102+
103+
``` purescript
104+
readlink :: forall eff. FilePath -> Aff (fs :: F.FS | eff) FilePath
105+
```
106+
107+
108+
Reads the value of a symlink.
109+
110+
111+
#### `realpath`
112+
113+
``` purescript
114+
realpath :: forall eff. FilePath -> Aff (fs :: F.FS | eff) FilePath
115+
```
116+
117+
118+
Find the canonicalized absolute location for a path.
119+
120+
121+
#### `realpath'`
122+
123+
``` purescript
124+
realpath' :: forall eff cache. FilePath -> { | cache } -> Aff (fs :: F.FS | eff) FilePath
125+
```
126+
127+
128+
Find the canonicalized absolute location for a path using a cache object
129+
for already resolved paths.
130+
131+
132+
#### `unlink`
133+
134+
``` purescript
135+
unlink :: forall eff. FilePath -> Aff (fs :: F.FS | eff) Unit
136+
```
137+
138+
139+
Deletes a file.
140+
141+
142+
#### `rmdir`
143+
144+
``` purescript
145+
rmdir :: forall eff. FilePath -> Aff (fs :: F.FS | eff) Unit
146+
```
147+
148+
149+
Deletes a directory.
150+
151+
152+
#### `mkdir`
153+
154+
``` purescript
155+
mkdir :: forall eff. FilePath -> Aff (fs :: F.FS | eff) Unit
156+
```
157+
158+
159+
Makes a new directory.
160+
161+
162+
#### `mkdir'`
163+
164+
``` purescript
165+
mkdir' :: forall eff. FilePath -> Perms -> Aff (fs :: F.FS | eff) Unit
166+
```
167+
168+
169+
Makes a new directory with the specified permissions.
170+
171+
172+
#### `readdir`
173+
174+
``` purescript
175+
readdir :: forall eff. FilePath -> Aff (fs :: F.FS | eff) [FilePath]
176+
```
177+
178+
179+
Reads the contents of a directory.
180+
181+
182+
#### `utimes`
183+
184+
``` purescript
185+
utimes :: forall eff. FilePath -> Date -> Date -> Aff (fs :: F.FS | eff) Unit
186+
```
187+
188+
189+
Sets the accessed and modified times for the specified file.
190+
191+
192+
#### `readFile`
193+
194+
``` purescript
195+
readFile :: forall eff. FilePath -> Aff (fs :: F.FS | eff) Buffer
196+
```
197+
198+
199+
Reads the entire contents of a file returning the result as a raw buffer.
200+
201+
202+
#### `readTextFile`
203+
204+
``` purescript
205+
readTextFile :: forall eff. Encoding -> FilePath -> Aff (fs :: F.FS | eff) String
206+
```
207+
208+
209+
Reads the entire contents of a text file with the specified encoding.
210+
211+
212+
#### `writeFile`
213+
214+
``` purescript
215+
writeFile :: forall eff. FilePath -> Buffer -> Aff (fs :: F.FS | eff) Unit
216+
```
217+
218+
219+
Writes a buffer to a file.
220+
221+
222+
#### `writeTextFile`
223+
224+
``` purescript
225+
writeTextFile :: forall eff. Encoding -> FilePath -> String -> Aff (fs :: F.FS | eff) Unit
226+
```
227+
228+
229+
Writes text to a file using the specified encoding.
230+
231+
232+
#### `appendFile`
233+
234+
``` purescript
235+
appendFile :: forall eff. FilePath -> Buffer -> Aff (fs :: F.FS | eff) Unit
236+
```
237+
238+
239+
Appends the contents of a buffer to a file.
240+
241+
242+
#### `appendTextFile`
243+
244+
``` purescript
245+
appendTextFile :: forall eff. Encoding -> FilePath -> String -> Aff (fs :: F.FS | eff) Unit
246+
```
247+
248+
249+
Appends text to a file using the specified encoding.
250+
251+
252+
#### `exists`
253+
254+
``` purescript
255+
exists :: forall eff. String -> Aff (fs :: F.FS | eff) Boolean
256+
```
257+
258+
259+
Check to see if a file exists.
260+
261+
262+
263+

example/example.purs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module Example.Main where
2+
3+
import Control.Monad (filterM)
4+
import Control.Functor
5+
import Data.String (charAt, fromChar)
6+
import Data.Maybe
7+
import Data.Array
8+
import Control.Monad.Trans
9+
import Control.Monad.Aff
10+
import Control.Monad.Eff.Class (liftEff)
11+
import qualified Node.Path as Path
12+
import qualified Debug.Trace as T
13+
import qualified Node.FS.Aff as FS
14+
import qualified Node.FS as FS
15+
import qualified Node.FS.Stats as FS
16+
17+
trace :: forall e a. (Show a) => a -> Aff (trace :: T.Trace | e) a
18+
trace a = do
19+
liftEff $ T.trace (show a)
20+
return a
21+
22+
main = launchAff do
23+
files <- FS.readdir "."
24+
files' <- flip filterM files \file -> do
25+
stat <- FS.stat file
26+
return $
27+
FS.isDirectory stat
28+
&& (maybe false (fromChar >>> (/= ".")) $ charAt 0 file)
29+
liftEff $ Debug.Trace.trace $ show files'

gulpfile.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
'use strict';
22

3+
/**
4+
* Add `./output` to path i.o. to load modules.
5+
* Warning: This is a hack
6+
* https://gist.github.com/branneman/8048520#6-the-hack
7+
*/
8+
process.env.NODE_PATH = __dirname + '/output';
9+
require('module').Module._initPaths();
10+
311
var gulp = require('gulp')
412
, purs = require('gulp-purescript')
513
, Promise = require('bluebird')
@@ -9,6 +17,7 @@ var gulp = require('gulp')
917

1018
var src = [ 'src/**/*.purs' ]
1119
, deps = [ 'bower_components/purescript-*/src/**/*.purs' ]
20+
, example = [ 'example/example.purs' ]
1221
, output = [ 'output' ]
1322
;
1423

@@ -25,3 +34,22 @@ gulp.task('make', [ 'psci' ], function() {
2534
.pipe(purs.pscMake({}))
2635
;
2736
});
37+
38+
gulp.task('docs', function() {
39+
return gulp
40+
.src(src)
41+
.pipe(purs.pscDocs({}))
42+
.pipe(gulp.dest('README.md'))
43+
;
44+
});
45+
46+
gulp.task('make:example', function() {
47+
return gulp
48+
.src(_.flatten([ src, example, deps ], false))
49+
.pipe(purs.pscMake({}))
50+
;
51+
});
52+
53+
gulp.task('example', ['make:example'], function() {
54+
require('Example.Main').main();
55+
});

src/Node/FS/Aff.purs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
-- |
2+
-- | [Node.FS][Node.FS] Wrappers for [purescript-aff][aff]
3+
-- |
4+
-- | The `Aff` monad let's you write async code with ease.
5+
-- |
6+
-- | Consider asynchronously listing only non-hidden directories:
7+
-- |
8+
-- | ``` purescript
9+
-- | main = launchAff do
10+
-- | files <- FS.readdir "."
11+
-- | files' <- flip filterM files \file -> do
12+
-- | stat <- FS.stat file
13+
-- | return $
14+
-- | FS.isDirectory stat
15+
-- | && (maybe false (fromChar >>> (/= ".")) $ charAt 0 file)
16+
-- | liftEff $ Debug.Trace.trace $ show files'
17+
-- | ```
18+
-- |
19+
-- | That was easy. For a working example, see [example.purs][example].
20+
-- | To build the example, run `gulp example`.
21+
-- |
22+
-- | [Node.FS]: http://github.com/purescript-node/purescript-node-fs
23+
-- | [aff]: https://github.com/slamdata/purescript-aff
24+
-- | [example]: http://github.com/purescript-node/purescript-node-fs-aff/blob/master/example/example.purs
25+
126
module Node.FS.Aff
227
( rename
328
, truncate

0 commit comments

Comments
 (0)