diff options
author | eric <thul.eric@gmail.com> | 2015-07-06 23:58:28 -0400 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2015-07-06 23:58:28 -0400 |
commit | 1d771135e825feaa1fba5177b60796578766b240 (patch) | |
tree | a063817b17ee2df146228cf66c4205c2d80f05be /src/FS.purs | |
parent | 4558c6cf7879207166b1cc013e2e8112f558bb1d (diff) | |
parent | 167c852f657b4746331c4f89e358a4a4876ced78 (diff) | |
download | purs-loader-1d771135e825feaa1fba5177b60796578766b240.tar.gz purs-loader-1d771135e825feaa1fba5177b60796578766b240.tar.zst purs-loader-1d771135e825feaa1fba5177b60796578766b240.zip |
Merge pull request #16 from ethul/topic/issue-11-and-14
Topic/issue 11 and 14
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) | ||