aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/FS.purs
diff options
context:
space:
mode:
authoreric <thul.eric@gmail.com>2015-04-12 11:35:25 -0400
committereric <thul.eric@gmail.com>2015-04-12 11:35:25 -0400
commit7d58cf78c770ef95858f90c6e89bd18653657a82 (patch)
treeebae7549b1a1b14e11fd5e2ad4dd66d901af81c8 /src/FS.purs
parent18ced1e0f031df444a5d85d72cd6843d826fef38 (diff)
parent94a23e744896b4440794de5d6cffedff1a1a2d56 (diff)
downloadpurs-loader-7d58cf78c770ef95858f90c6e89bd18653657a82.tar.gz
purs-loader-7d58cf78c770ef95858f90c6e89bd18653657a82.tar.zst
purs-loader-7d58cf78c770ef95858f90c6e89bd18653657a82.zip
Merge pull request #8 from ethul/topic/purescript-rewrite
Topic/purescript rewrite
Diffstat (limited to 'src/FS.purs')
-rw-r--r--src/FS.purs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/FS.purs b/src/FS.purs
new file mode 100644
index 0000000..68fe2f9
--- /dev/null
+++ b/src/FS.purs
@@ -0,0 +1,45 @@
1module PursLoader.FS
2 ( FS()
3 , readFileUtf8
4 , readFileUtf8Sync
5 ) where
6
7import Control.Monad.Aff (Aff(), makeAff)
8import Control.Monad.Eff (Eff())
9import Control.Monad.Eff.Exception (Error())
10
11import Data.Function
12
13foreign import data FS :: !
14
15readFileUtf8 :: forall eff. String -> Aff (fs :: FS | eff) String
16readFileUtf8 filepath = makeAff $ runFn3 readFileUtf8Fn filepath
17
18readFileUtf8Sync :: forall eff. String -> Eff (fs :: FS | eff) String
19readFileUtf8Sync filepath = readFileUtf8SyncFn filepath
20
21foreign import readFileUtf8Fn """
22function readFileUtf8Fn(filepath, errback, callback) {
23 return function(){
24 var fs = require('fs');
25
26 fs.readFile(filepath, 'utf-8', function(e, data){
27 if (e) errback(e)();
28 else callback(data)();
29 });
30 };
31}
32""" :: forall eff. Fn3 String
33 (Error -> Eff (fs :: FS | eff) Unit)
34 (String -> Eff (fs :: FS | eff) Unit)
35 (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)