diff options
author | eric <thul.eric@gmail.com> | 2015-08-11 21:23:46 -0400 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2015-08-11 21:23:46 -0400 |
commit | 7226ff961c104037e8e5d3705949e2e9d58a6727 (patch) | |
tree | 555547366ccadfe71689b95a6b16b855b6173364 /src/PursLoader/FS.js | |
parent | eae2e182cec2d521166e5775294b52300c42f069 (diff) | |
parent | 07de44be15efb0ca9a2d1443ab1e91076a25409c (diff) | |
download | purs-loader-7226ff961c104037e8e5d3705949e2e9d58a6727.tar.gz purs-loader-7226ff961c104037e8e5d3705949e2e9d58a6727.tar.zst purs-loader-7226ff961c104037e8e5d3705949e2e9d58a6727.zip |
Merge pull request #27 from ethul/topic/issue-26
Topic/issue 26
Diffstat (limited to 'src/PursLoader/FS.js')
-rw-r--r-- | src/PursLoader/FS.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/PursLoader/FS.js b/src/PursLoader/FS.js new file mode 100644 index 0000000..1a7f5b0 --- /dev/null +++ b/src/PursLoader/FS.js | |||
@@ -0,0 +1,36 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | // module PursLoader.FS | ||
4 | |||
5 | var fs = require('fs'); | ||
6 | |||
7 | var async = require('async'); | ||
8 | |||
9 | function writeFileUtf8Fn(filepath, contents, errback, callback) { | ||
10 | return function(){ | ||
11 | fs.writeFile(filepath, contents, function(error){ | ||
12 | if (error) errback(error)(); | ||
13 | else callback()(); | ||
14 | }); | ||
15 | }; | ||
16 | } | ||
17 | |||
18 | function findFileUtf8Fn(nothing, just, regex, filepaths, errback, callback) { | ||
19 | return function(){ | ||
20 | function findFile(filepath, callback) { | ||
21 | fs.readFile(filepath, {encoding: 'utf-8'}, function(error, result){ | ||
22 | if (error) callback(false); | ||
23 | else callback(regex.test(result)); | ||
24 | }); | ||
25 | } | ||
26 | |||
27 | async.detect(filepaths, findFile, function(result){ | ||
28 | if (!result) callback(nothing)(); | ||
29 | else callback(just(result))(); | ||
30 | }); | ||
31 | }; | ||
32 | } | ||
33 | |||
34 | exports.writeFileUtf8Fn = writeFileUtf8Fn; | ||
35 | |||
36 | exports.findFileUtf8Fn = findFileUtf8Fn; | ||