1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
'use strict';
// module PursLoader.FS
var fs = require('fs');
var async = require('async');
function writeFileUtf8Fn(filepath, contents, errback, callback) {
return function(){
fs.writeFile(filepath, contents, function(error){
if (error) errback(error)();
else callback()();
});
};
}
function findFileUtf8Fn(nothing, just, regex, filepaths, errback, callback) {
return function(){
function findFile(filepath, callback) {
fs.readFile(filepath, {encoding: 'utf-8'}, function(error, result){
if (error) callback(false);
else callback(regex.test(result));
});
}
async.detect(filepaths, findFile, function(result){
if (!result) callback(nothing)();
else callback(just(result))();
});
};
}
exports.writeFileUtf8Fn = writeFileUtf8Fn;
exports.findFileUtf8Fn = findFileUtf8Fn;
|