aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PursLoader/FS.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/PursLoader/FS.js')
-rw-r--r--src/PursLoader/FS.js36
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
5var fs = require('fs');
6
7var async = require('async');
8
9function 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
18function 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
34exports.writeFileUtf8Fn = writeFileUtf8Fn;
35
36exports.findFileUtf8Fn = findFileUtf8Fn;