aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/FS.purs
diff options
context:
space:
mode:
Diffstat (limited to 'src/FS.purs')
-rw-r--r--src/FS.purs35
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 @@
1module PursLoader.FS 1module PursLoader.FS
2 ( FS() 2 ( FS()
3 , readFileUtf8 3 , writeFileUtf8
4 , readFileUtf8Sync
5 ) where 4 ) where
6 5
7import Control.Monad.Aff (Aff(), makeAff) 6import Control.Monad.Aff (Aff(), makeAff)
@@ -12,34 +11,22 @@ import Data.Function
12 11
13foreign import data FS :: ! 12foreign import data FS :: !
14 13
15readFileUtf8 :: forall eff. String -> Aff (fs :: FS | eff) String 14writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit
16readFileUtf8 filepath = makeAff $ runFn3 readFileUtf8Fn filepath 15writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents
17 16
18readFileUtf8Sync :: forall eff. String -> Eff (fs :: FS | eff) String 17foreign import writeFileUtf8Fn """
19readFileUtf8Sync filepath = readFileUtf8SyncFn filepath 18function writeFileUtf8Fn(filepath, contents, errback, callback) {
20
21foreign import readFileUtf8Fn """
22function 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
37foreign import readFileUtf8SyncFn """
38function 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)