diff options
Diffstat (limited to 'src/FS.purs')
-rw-r--r-- | src/FS.purs | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/src/FS.purs b/src/FS.purs index 68fe2f9..a56fe26 100644 --- a/src/FS.purs +++ b/src/FS.purs | |||
@@ -1,7 +1,6 @@ | |||
1 | module PursLoader.FS | 1 | module PursLoader.FS |
2 | ( FS() | 2 | ( FS() |
3 | , readFileUtf8 | 3 | , writeFileUtf8 |
4 | , readFileUtf8Sync | ||
5 | ) where | 4 | ) where |
6 | 5 | ||
7 | import Control.Monad.Aff (Aff(), makeAff) | 6 | import Control.Monad.Aff (Aff(), makeAff) |
@@ -12,34 +11,22 @@ import Data.Function | |||
12 | 11 | ||
13 | foreign import data FS :: ! | 12 | foreign import data FS :: ! |
14 | 13 | ||
15 | readFileUtf8 :: forall eff. String -> Aff (fs :: FS | eff) String | 14 | writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit |
16 | readFileUtf8 filepath = makeAff $ runFn3 readFileUtf8Fn filepath | 15 | writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents |
17 | 16 | ||
18 | readFileUtf8Sync :: forall eff. String -> Eff (fs :: FS | eff) String | 17 | foreign import writeFileUtf8Fn """ |
19 | readFileUtf8Sync filepath = readFileUtf8SyncFn filepath | 18 | function writeFileUtf8Fn(filepath, contents, errback, callback) { |
20 | |||
21 | foreign import readFileUtf8Fn """ | ||
22 | function readFileUtf8Fn(filepath, errback, callback) { | ||
23 | return function(){ | 19 | return function(){ |
24 | var fs = require('fs'); | 20 | var fs = require('fs'); |
25 | 21 | ||
26 | fs.readFile(filepath, 'utf-8', function(e, data){ | 22 | fs.writeFile(filepath, contents, function(error){ |
27 | if (e) errback(e)(); | 23 | if (error) errback(error)(); |
28 | else callback(data)(); | 24 | else callback()(); |
29 | }); | 25 | }); |
30 | }; | 26 | }; |
31 | } | 27 | } |
32 | """ :: forall eff. Fn3 String | 28 | """ :: forall eff. Fn4 String |
29 | String | ||
33 | (Error -> Eff (fs :: FS | eff) Unit) | 30 | (Error -> Eff (fs :: FS | eff) Unit) |
34 | (String -> Eff (fs :: FS | eff) Unit) | 31 | (Unit -> Eff (fs :: FS | eff) Unit) |
35 | (Eff (fs :: FS | eff) Unit) | 32 | (Eff (fs :: FS | eff) Unit) |
36 | |||
37 | foreign import readFileUtf8SyncFn """ | ||
38 | function readFileUtf8SyncFn(filepath) { | ||
39 | return function(){ | ||
40 | var fs = require('fs'); | ||
41 | |||
42 | return fs.readFileSync(filepath, {encoding: 'utf-8'}); | ||
43 | }; | ||
44 | } | ||
45 | """ :: forall eff. String -> (Eff (fs :: FS | eff) String) | ||