123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- "use strict";
- function SyncAsyncFileSystemDecorator(fs) {
- this.fs = fs;
- this.lstat = undefined;
- this.lstatSync = undefined;
- const lstatSync = fs.lstatSync;
- if (lstatSync) {
- this.lstat =
-
- (
- (arg, options, callback) => {
- let result;
- try {
- result = (callback)
- ? lstatSync.call(fs, arg, options)
- : lstatSync.call(fs, arg);
- } catch (e) {
- return (callback || options)(
- (e)
- );
- }
- (callback || options)(null, (result));
- }
- );
- this.lstatSync =
-
- ((arg, options) => lstatSync.call(fs, arg, options));
- }
- this.stat =
-
- (
- (arg, options, callback) => {
- let result;
- try {
- result = (callback)
- ? fs.statSync(arg, options)
- : fs.statSync(arg);
- } catch (e) {
- return (callback || options)(
- (e)
- );
- }
- (callback || options)(null, (result));
- }
- );
- this.statSync =
-
- ((arg, options) => fs.statSync(arg, options));
- this.readdir =
-
- (
- (arg, options, callback) => {
- let result;
- try {
- result = (callback)
- ? fs.readdirSync(
- arg,
-
- (options)
- )
- : fs.readdirSync(arg);
- } catch (e) {
- return (callback || options)(
- (e)
- );
- }
- (callback || options)(null, (result));
- }
- );
- this.readdirSync =
-
- (
- (arg, options) =>
- fs.readdirSync(
- arg,
- (options)
- )
- );
- this.readFile =
-
- (
- (arg, options, callback) => {
- let result;
- try {
- result = (callback)
- ? fs.readFileSync(arg, options)
- : fs.readFileSync(arg);
- } catch (e) {
- return (callback || options)(
- (e)
- );
- }
- (callback || options)(null, (result));
- }
- );
- this.readFileSync =
-
- ((arg, options) => fs.readFileSync(arg, options));
- this.readlink =
-
- (
- (arg, options, callback) => {
- let result;
- try {
- result = (callback)
- ? fs.readlinkSync(
- arg,
-
- (options)
- )
- : fs.readlinkSync(arg);
- } catch (e) {
- return (callback || options)(
- (e)
- );
- }
- (callback || options)(null, (result));
- }
- );
- this.readlinkSync =
-
- (
- (arg, options) =>
- fs.readlinkSync(
- arg,
- (options)
- )
- );
- this.readJson = undefined;
- this.readJsonSync = undefined;
- const readJsonSync = fs.readJsonSync;
- if (readJsonSync) {
- this.readJson =
-
- (
- (arg, callback) => {
- let result;
- try {
- result = readJsonSync.call(fs, arg);
- } catch (e) {
- return callback(
- (e)
- );
- }
- callback(null, result);
- }
- );
- this.readJsonSync =
-
- (arg => readJsonSync.call(fs, arg));
- }
- this.realpath = undefined;
- this.realpathSync = undefined;
- const realpathSync = fs.realpathSync;
- if (realpathSync) {
- this.realpath =
-
- (
- (arg, options, callback) => {
- let result;
- try {
- result = (callback)
- ? realpathSync.call(
- fs,
- arg,
-
- (options)
- )
- : realpathSync.call(fs, arg);
- } catch (e) {
- return (callback || options)(
- (e)
- );
- }
- (callback || options)(null, (result));
- }
- );
- this.realpathSync =
-
- (
- (arg, options) =>
- realpathSync.call(
- fs,
- arg,
-
- (options)
- )
- );
- }
- }
- module.exports = SyncAsyncFileSystemDecorator;
|