1 | // dumb, inefficient, synchronous module.
|
2 | // This is a bad idea, but super useful for things
|
3 | // where performance isn't a big deal, like in a build
|
4 | // file or something.
|
5 |
|
6 | // You can lazily just attempt to read a file path that
|
7 | // may or may not exist.
|
8 |
|
9 | // for example:
|
10 | /*
|
11 | var readFile = require('readfilesync');
|
12 |
|
13 | // this won't ever blow up!
|
14 | var file = readFile('some/path');
|
15 |
|
16 | // now we can just do
|
17 | if (!file) {
|
18 | // handle case of file not present
|
19 | }
|
20 |
|
21 | */
|
22 |
|
23 |
|
24 |
|
25 | var fs = require('fs');
|
26 |
|
27 |
|
28 | module.exports = function (path, encoding) {
|
29 | var res;
|
30 | try {
|
31 | res = fs.readFileSync(path, encoding || 'utf8');
|
32 | } catch (e) {}
|
33 | return res;
|
34 | }
|