Last change
on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.readFile = readFile;
|
---|
| 7 | exports.readFileSync = readFileSync;
|
---|
| 8 |
|
---|
| 9 | var _fs = _interopRequireDefault(require("fs"));
|
---|
| 10 |
|
---|
| 11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 12 |
|
---|
| 13 | async function fsReadFileAsync(pathname, encoding) {
|
---|
| 14 | return new Promise((resolve, reject) => {
|
---|
| 15 | _fs.default.readFile(pathname, encoding, (error, contents) => {
|
---|
| 16 | if (error) {
|
---|
| 17 | reject(error);
|
---|
| 18 | return;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | resolve(contents);
|
---|
| 22 | });
|
---|
| 23 | });
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | async function readFile(filepath, options = {}) {
|
---|
| 27 | const throwNotFound = options.throwNotFound === true;
|
---|
| 28 |
|
---|
| 29 | try {
|
---|
| 30 | const content = await fsReadFileAsync(filepath, 'utf8');
|
---|
| 31 | return content;
|
---|
| 32 | } catch (error) {
|
---|
| 33 | if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) {
|
---|
| 34 | return null;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | throw error;
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | function readFileSync(filepath, options = {}) {
|
---|
| 42 | const throwNotFound = options.throwNotFound === true;
|
---|
| 43 |
|
---|
| 44 | try {
|
---|
| 45 | const content = _fs.default.readFileSync(filepath, 'utf8');
|
---|
| 46 |
|
---|
| 47 | return content;
|
---|
| 48 | } catch (error) {
|
---|
| 49 | if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) {
|
---|
| 50 | return null;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | throw error;
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | //# sourceMappingURL=readFile.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.