1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports["default"] = patchFs;
|
---|
7 |
|
---|
8 | var _lists = require("./util/lists");
|
---|
9 |
|
---|
10 | function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
---|
11 |
|
---|
12 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
---|
13 |
|
---|
14 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
---|
15 |
|
---|
16 | function patchFs(vol) {
|
---|
17 | var fs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : require('fs');
|
---|
18 | var bkp = {};
|
---|
19 |
|
---|
20 | var patch = function patch(key, newValue) {
|
---|
21 | bkp[key] = fs[key];
|
---|
22 | fs[key] = newValue;
|
---|
23 | };
|
---|
24 |
|
---|
25 | var patchMethod = function patchMethod(key) {
|
---|
26 | return patch(key, vol[key].bind(vol));
|
---|
27 | };
|
---|
28 |
|
---|
29 | var _iterator = _createForOfIteratorHelper(_lists.fsProps),
|
---|
30 | _step;
|
---|
31 |
|
---|
32 | try {
|
---|
33 | for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
---|
34 | var prop = _step.value;
|
---|
35 | if (typeof vol[prop] !== 'undefined') patch(prop, vol[prop]);
|
---|
36 | }
|
---|
37 | } catch (err) {
|
---|
38 | _iterator.e(err);
|
---|
39 | } finally {
|
---|
40 | _iterator.f();
|
---|
41 | }
|
---|
42 |
|
---|
43 | if (typeof vol.StatWatcher === 'function') {
|
---|
44 | patch('StatWatcher', vol.FSWatcher.bind(null, vol));
|
---|
45 | }
|
---|
46 |
|
---|
47 | if (typeof vol.FSWatcher === 'function') {
|
---|
48 | patch('FSWatcher', vol.StatWatcher.bind(null, vol));
|
---|
49 | }
|
---|
50 |
|
---|
51 | if (typeof vol.ReadStream === 'function') {
|
---|
52 | patch('ReadStream', vol.ReadStream.bind(null, vol));
|
---|
53 | }
|
---|
54 |
|
---|
55 | if (typeof vol.WriteStream === 'function') {
|
---|
56 | patch('WriteStream', vol.WriteStream.bind(null, vol));
|
---|
57 | }
|
---|
58 |
|
---|
59 | if (typeof vol._toUnixTimestamp === 'function') patchMethod('_toUnixTimestamp');
|
---|
60 |
|
---|
61 | var _iterator2 = _createForOfIteratorHelper(_lists.fsAsyncMethods),
|
---|
62 | _step2;
|
---|
63 |
|
---|
64 | try {
|
---|
65 | for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
---|
66 | var method = _step2.value;
|
---|
67 | if (typeof vol[method] === 'function') patchMethod(method);
|
---|
68 | }
|
---|
69 | } catch (err) {
|
---|
70 | _iterator2.e(err);
|
---|
71 | } finally {
|
---|
72 | _iterator2.f();
|
---|
73 | }
|
---|
74 |
|
---|
75 | var _iterator3 = _createForOfIteratorHelper(_lists.fsSyncMethods),
|
---|
76 | _step3;
|
---|
77 |
|
---|
78 | try {
|
---|
79 | for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
---|
80 | var _method = _step3.value;
|
---|
81 | if (typeof vol[_method] === 'function') patchMethod(_method);
|
---|
82 | }
|
---|
83 | } catch (err) {
|
---|
84 | _iterator3.e(err);
|
---|
85 | } finally {
|
---|
86 | _iterator3.f();
|
---|
87 | }
|
---|
88 |
|
---|
89 | return function unpatch() {
|
---|
90 | for (var key in bkp) {
|
---|
91 | fs[key] = bkp[key];
|
---|
92 | }
|
---|
93 | };
|
---|
94 | }
|
---|
95 |
|
---|
96 | ; |
---|