@wocker/ws 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +1 -1
  2. package/lib/App.d.ts +4 -3
  3. package/lib/App.js +98 -77
  4. package/lib/controllers/ImageController.d.ts +2 -2
  5. package/lib/controllers/ImageController.js +27 -27
  6. package/lib/controllers/PluginController.d.ts +2 -2
  7. package/lib/controllers/PluginController.js +78 -56
  8. package/lib/controllers/PresetController.d.ts +3 -1
  9. package/lib/controllers/PresetController.js +155 -136
  10. package/lib/controllers/ProjectController.d.ts +5 -5
  11. package/lib/controllers/ProjectController.js +653 -603
  12. package/lib/controllers/ProxyController.d.ts +4 -1
  13. package/lib/controllers/ProxyController.js +269 -245
  14. package/lib/controllers/index.js +19 -58
  15. package/lib/env.js +33 -15
  16. package/lib/index.d.ts +2 -0
  17. package/lib/index.js +30 -16
  18. package/lib/makes/Controller.js +4 -8
  19. package/lib/makes/DI.d.ts +7 -0
  20. package/lib/makes/DI.js +27 -0
  21. package/lib/makes/Docker.js +298 -382
  22. package/lib/makes/FS.js +328 -304
  23. package/lib/makes/LineConvertStream.js +37 -40
  24. package/lib/makes/Logger.d.ts +9 -1
  25. package/lib/makes/Logger.js +22 -11
  26. package/lib/makes/Model.js +8 -12
  27. package/lib/makes/MySQL.js +6 -27
  28. package/lib/makes/Plugin.d.ts +1 -1
  29. package/lib/makes/Plugin.js +55 -37
  30. package/lib/makes/Preset.d.ts +46 -0
  31. package/lib/makes/Preset.js +33 -0
  32. package/lib/makes/Project.d.ts +45 -0
  33. package/lib/makes/Project.js +127 -0
  34. package/lib/makes/Repository.js +18 -21
  35. package/lib/makes/index.d.ts +3 -0
  36. package/lib/makes/index.js +23 -69
  37. package/lib/plugins/ElasticSearchPlugin.d.ts +3 -1
  38. package/lib/plugins/ElasticSearchPlugin.js +66 -66
  39. package/lib/plugins/LocaltunnelPlugin.d.ts +2 -2
  40. package/lib/plugins/LocaltunnelPlugin.js +256 -257
  41. package/lib/plugins/MaildevPlugin.d.ts +2 -2
  42. package/lib/plugins/MaildevPlugin.js +45 -44
  43. package/lib/plugins/MongodbPlugin.d.ts +2 -2
  44. package/lib/plugins/MongodbPlugin.js +303 -248
  45. package/lib/plugins/NgrokPlugin.d.ts +2 -2
  46. package/lib/plugins/NgrokPlugin.js +221 -231
  47. package/lib/plugins/PageKitePlugin.d.ts +2 -2
  48. package/lib/plugins/PageKitePlugin.js +150 -149
  49. package/lib/plugins/PostgresPlugin.d.ts +1 -1
  50. package/lib/plugins/PostgresPlugin.js +115 -89
  51. package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
  52. package/lib/plugins/ProxmoxPlugin.js +50 -38
  53. package/lib/plugins/RedisPlugin.d.ts +3 -1
  54. package/lib/plugins/RedisPlugin.js +73 -72
  55. package/lib/plugins/index.js +25 -103
  56. package/lib/services/AppConfigService.d.ts +3 -3
  57. package/lib/services/AppConfigService.js +162 -157
  58. package/lib/services/AppEventsService.js +26 -24
  59. package/lib/services/DockerService.d.ts +37 -2
  60. package/lib/services/DockerService.js +185 -205
  61. package/lib/services/LogService.d.ts +3 -2
  62. package/lib/services/LogService.js +33 -34
  63. package/lib/services/PluginService.d.ts +2 -1
  64. package/lib/services/PluginService.js +11 -14
  65. package/lib/services/PresetService.d.ts +8 -3
  66. package/lib/services/PresetService.js +60 -59
  67. package/lib/services/ProjectService.d.ts +11 -4
  68. package/lib/services/ProjectService.js +140 -129
  69. package/lib/services/index.js +21 -80
  70. package/lib/types/Config.d.ts +4 -3
  71. package/lib/types/Config.js +1 -4
  72. package/lib/types/EnvConfig.js +1 -4
  73. package/lib/types/index.js +16 -25
  74. package/lib/utils/buildOptions.js +5 -8
  75. package/lib/utils/demuxOutput.js +16 -20
  76. package/lib/utils/escapeRegExp.js +4 -7
  77. package/lib/utils/exec.js +38 -39
  78. package/lib/utils/fetch.js +46 -30
  79. package/lib/utils/followProgress.js +66 -77
  80. package/lib/utils/format-size-units.js +16 -16
  81. package/lib/utils/get-config.d.ts +1 -1
  82. package/lib/utils/get-config.js +13 -16
  83. package/lib/utils/get-cursor-position.js +22 -29
  84. package/lib/utils/image-build.js +35 -23
  85. package/lib/utils/index.js +32 -191
  86. package/lib/utils/injectVariables.js +10 -13
  87. package/lib/utils/parse-table.js +20 -23
  88. package/lib/utils/set-config.d.ts +1 -1
  89. package/lib/utils/set-config.js +12 -15
  90. package/lib/utils/spawn.js +17 -20
  91. package/lib/utils/tty.js +2 -6
  92. package/lib/utils/volumeFormat.js +5 -12
  93. package/lib/utils/volumeParse.js +10 -13
  94. package/package.json +13 -39
  95. package/presets/bun/Dockerfile +11 -0
  96. package/presets/bun/config.json +3 -0
  97. package/presets/node/Dockerfile +4 -2
  98. package/presets/php-apache/Dockerfile +3 -2
  99. package/.github/workflows/publish.yml +0 -31
  100. package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
package/lib/makes/FS.js CHANGED
@@ -1,320 +1,344 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
5
17
  });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
6
26
  exports.FS = void 0;
7
- var fs = _interopRequireWildcard(require("fs"));
8
- var Path = _interopRequireWildcard(require("path"));
9
- var _readableStream = require("readable-stream");
10
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
27
+ const fs = __importStar(require("fs"));
28
+ const Path = __importStar(require("path"));
29
+ const readable_stream_1 = require("readable-stream");
12
30
  class FS {
13
- static async access(path) {
14
- return new Promise((resolve, reject) => {
15
- fs.access(path, err => {
16
- if (!err) {
17
- resolve(null);
18
- } else {
19
- reject(err);
20
- }
21
- });
22
- });
23
- }
24
-
25
- /**
26
- * Asynchronously tests whether or not the given path exists by checking with the file system.
27
- * @param path path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
28
- */
29
- static async exists(path) {
30
- return new Promise(resolve => {
31
- fs.exists(path, exists => {
32
- resolve(exists);
33
- });
34
- });
35
- }
36
- static existsSync(path) {
37
- return fs.existsSync(path);
38
- }
39
- static async mkdir(dirPath, options = {}) {
40
- return new Promise((resolve, reject) => {
41
- fs.mkdir(dirPath, options, err => {
42
- if (!err) {
43
- resolve();
44
- } else {
45
- reject(err);
46
- }
47
- });
48
- });
49
- }
50
- static mkdirSync(path, options) {
51
- return fs.mkdirSync(path, options);
52
- }
53
- static async readdir(path) {
54
- return new Promise((resolve, reject) => {
55
- fs.readdir(path, (err, files) => {
56
- if (!err) {
57
- resolve(files);
58
- } else {
59
- reject(err);
60
- }
61
- });
62
- });
63
- }
64
- static async readdirFiles(path, options) {
65
- const {
66
- recursive = false
67
- } = options || {};
68
- if (recursive) {
69
- const names = await FS.readdir(path);
70
- let res = [];
71
- for (const name of names) {
72
- const filePath = Path.join(path, name);
73
- let sub = [name];
74
- const stats = await FS.stat(filePath);
75
- if (stats.isDirectory()) {
76
- sub = (await FS.readdirFiles(filePath, {
77
- recursive: true
78
- })).map(subName => {
79
- return Path.join(name, subName);
80
- });
81
- }
82
- res = [...res, ...sub];
83
- }
84
- return res;
31
+ static async access(path) {
32
+ return new Promise((resolve, reject) => {
33
+ fs.access(path, (err) => {
34
+ if (!err) {
35
+ resolve(null);
36
+ }
37
+ else {
38
+ reject(err);
39
+ }
40
+ });
41
+ });
85
42
  }
86
- return new Promise((resolve, reject) => {
87
- fs.readdir(path, {
88
- withFileTypes: true
89
- }, (err, files) => {
90
- if (err) {
91
- return reject(err);
92
- }
93
- const names = files.filter(dirent => {
94
- return dirent.isFile();
95
- }).map(dirent => {
96
- return dirent.name;
43
+ static async exists(path) {
44
+ return new Promise((resolve) => {
45
+ fs.exists(path, (exists) => {
46
+ resolve(exists);
47
+ });
97
48
  });
98
- resolve(names);
99
- });
100
- });
101
- }
102
- static async appendFile(path, data, options) {
103
- return new Promise((resolve, reject) => {
104
- fs.appendFile(path, data, options, (error, data) => {
105
- if (error) {
106
- reject(error);
107
- } else {
108
- resolve(data);
109
- }
110
- });
111
- });
112
- }
113
- static appendFileSync(path, data, options) {
114
- return fs.appendFileSync(path, data, options);
115
- }
116
- static read() {
117
- //
118
- }
119
- static async readBytes(filePath, position = 0, size) {
120
- if (position < 0 && typeof size === "undefined") {
121
- const stats = await FS.stat(filePath);
122
- size = BigInt(position) * -1n;
123
- position = BigInt(stats.size) - size;
124
- if (position < 0n) {
125
- position = 0;
126
- }
127
- } else if (typeof size === "undefined") {
128
- const stats = await FS.stat(filePath);
129
- if (typeof stats.size !== "bigint" && typeof position !== "bigint") {
130
- size = stats.size - position;
131
- } else {
132
- size = BigInt(stats.size) - BigInt(position);
133
- }
134
49
  }
135
- if (size < 0n) {
136
- // throw Error(`Buffer size ${size}`);
137
-
138
- return Buffer.alloc(0);
50
+ static existsSync(path) {
51
+ return fs.existsSync(path);
139
52
  }
140
- const buffer = Buffer.alloc(Number(size));
141
- return new Promise((resolve, reject) => {
142
- fs.open(filePath, (err, file) => {
143
- if (err) {
144
- reject(err);
145
- return;
146
- }
147
- fs.read(file, buffer, 0, buffer.length, position, (err, bytesRead, buffer) => {
148
- if (err) {
149
- reject(err);
150
- return;
151
- }
152
- resolve(buffer);
53
+ static async mkdir(dirPath, options = {}) {
54
+ return new Promise((resolve, reject) => {
55
+ fs.mkdir(dirPath, options, (err) => {
56
+ if (!err) {
57
+ resolve();
58
+ }
59
+ else {
60
+ reject(err);
61
+ }
62
+ });
153
63
  });
154
- });
155
- });
156
- }
157
- static async readFile(filePath) {
158
- return new Promise((resolve, reject) => {
159
- fs.readFile(filePath, (err, data) => {
160
- if (!err) {
161
- resolve(data);
162
- } else {
163
- reject(err);
164
- }
165
- });
166
- });
167
- }
168
- static readFileSync(filePath) {
169
- return fs.readFileSync(filePath);
170
- }
171
- static async writeFile(filePath, data, options) {
172
- return new Promise((resolve, reject) => {
173
- fs.writeFile(filePath, data, options, err => {
174
- if (!err) {
175
- resolve();
176
- } else {
177
- reject(err);
178
- }
179
- });
180
- });
181
- }
182
- static writeFileSync(path, data, options) {
183
- return fs.writeFileSync(path, data, options);
184
- }
185
- static createWriteStream(path) {
186
- return fs.createWriteStream(path);
187
- }
188
- static async readJSON(...paths) {
189
- const res = await new Promise((resolve, reject) => {
190
- const filePath = Path.join(...paths);
191
- fs.readFile(filePath, (err, data) => {
192
- if (err) {
193
- reject(err);
194
- return;
195
- }
196
- resolve(data);
197
- });
198
- });
199
- return JSON.parse(res.toString());
200
- }
201
- static async writeJSON(filePath, data) {
202
- const json = JSON.stringify(data, null, 4);
203
- return FS.writeFile(filePath, json);
204
- }
205
- static async unlink(filePath) {
206
- return new Promise((resolve, reject) => {
207
- fs.unlink(filePath, err => {
208
- if (!err) {
209
- resolve();
210
- } else {
211
- reject(err);
212
- }
213
- });
214
- });
215
- }
216
- static watch(filename, options) {
217
- return fs.watch(filename, options);
218
- }
219
- static stat(filename, options) {
220
- return new Promise((resolve, reject) => {
221
- fs.stat(filename, options, (err, stats) => {
222
- if (err) {
223
- reject(err);
224
- } else {
225
- resolve(stats);
226
- }
227
- });
228
- });
229
- }
230
- static createReadStream(path, options) {
231
- return fs.createReadStream(path, options);
232
- }
233
- static createReadLinesStream(path, count) {
234
- const write = new _readableStream.PassThrough();
235
- (async () => {
236
- if (typeof count === "undefined" || count > 0) {
237
- const stats = await FS.stat(path);
238
- const resLines = [""];
239
- let position = 0n;
240
- while (position < stats.size) {
241
- let size = BigInt(count ? 64 * count : 255);
242
- if (position + size > stats.size) {
243
- size = BigInt(stats.size) - position;
244
- }
245
- const buffer = await FS.readBytes(path, position, size);
246
- const lines = buffer.toString("utf-8").split("\n");
247
- position += size;
248
- for (let i = 0; i < lines.length; i++) {
249
- const line = lines[i];
250
- if (i === 0) {
251
- resLines[resLines.length - 1] = (resLines[resLines.length - 1] || "") + line;
252
- } else {
253
- resLines.push(line);
64
+ }
65
+ static mkdirSync(path, options) {
66
+ return fs.mkdirSync(path, options);
67
+ }
68
+ static async readdir(path) {
69
+ return new Promise((resolve, reject) => {
70
+ fs.readdir(path, (err, files) => {
71
+ if (!err) {
72
+ resolve(files);
73
+ }
74
+ else {
75
+ reject(err);
76
+ }
77
+ });
78
+ });
79
+ }
80
+ static async readdirFiles(path, options) {
81
+ const { recursive = false } = options || {};
82
+ if (recursive) {
83
+ const names = await FS.readdir(path);
84
+ let res = [];
85
+ for (const name of names) {
86
+ const filePath = Path.join(path, name);
87
+ let sub = [
88
+ name
89
+ ];
90
+ const stats = await FS.stat(filePath);
91
+ if (stats.isDirectory()) {
92
+ sub = (await FS.readdirFiles(filePath, { recursive: true })).map((subName) => {
93
+ return Path.join(name, subName);
94
+ });
95
+ }
96
+ res = [
97
+ ...res,
98
+ ...sub
99
+ ];
254
100
  }
255
- }
256
- if (resLines.length > count + 1) {
257
- break;
258
- }
101
+ return res;
259
102
  }
260
- for (let i = 0; i < (count || resLines.length); i++) {
261
- write.write(resLines[i]);
262
- }
263
- } else if (count < 0) {
264
- const stats = await FS.stat(path);
265
- const resLines = [""];
266
- let position = BigInt(stats.size);
267
- while (position > 0n) {
268
- // let size = BigInt(64 * count * -1);
269
- let size = BigInt(2 * count * -1);
270
- position -= size;
271
- if (position < 0) {
272
- size = position + size;
273
- position = 0n;
274
- }
275
- const buffer = await FS.readBytes(path, position, size);
276
- const lines = buffer.toString("utf-8").split("\n").reverse();
277
- for (let i = 0; i < lines.length; i++) {
278
- const line = lines[i];
279
- if (i === 0) {
280
- resLines[0] = line + (resLines[0] || "");
281
- } else {
282
- resLines.unshift(line);
103
+ return new Promise((resolve, reject) => {
104
+ fs.readdir(path, {
105
+ withFileTypes: true
106
+ }, (err, files) => {
107
+ if (err) {
108
+ return reject(err);
109
+ }
110
+ const names = files.filter((dirent) => {
111
+ return dirent.isFile();
112
+ }).map((dirent) => {
113
+ return dirent.name;
114
+ });
115
+ resolve(names);
116
+ });
117
+ });
118
+ }
119
+ static async appendFile(path, data, options) {
120
+ return new Promise((resolve, reject) => {
121
+ fs.appendFile(path, data, options, (error, data) => {
122
+ if (error) {
123
+ reject(error);
124
+ }
125
+ else {
126
+ resolve(data);
127
+ }
128
+ });
129
+ });
130
+ }
131
+ static appendFileSync(path, data, options) {
132
+ return fs.appendFileSync(path, data, options);
133
+ }
134
+ static read() {
135
+ }
136
+ static async readBytes(filePath, position = 0, size) {
137
+ if (position < 0 && typeof size === "undefined") {
138
+ const stats = await FS.stat(filePath);
139
+ size = BigInt(position) * -1n;
140
+ position = BigInt(stats.size) - size;
141
+ if (position < 0n) {
142
+ position = 0;
283
143
  }
284
- }
285
- if (resLines.length > count * -1 + 1) {
286
- break;
287
- }
288
- }
289
- const lines = resLines.slice(count - 1);
290
- for (let i = 0; i < lines.length; i++) {
291
- write.write(lines[i]);
292
144
  }
293
- write.end();
294
- }
295
- })();
296
- return write;
297
- }
298
- static async copyFile(src, dest) {
299
- new Promise((resolve, reject) => {
300
- fs.copyFile(src, dest, err => {
301
- if (!err) {
302
- resolve(undefined);
303
- } else {
304
- reject(err);
145
+ else if (typeof size === "undefined") {
146
+ const stats = await FS.stat(filePath);
147
+ if (typeof stats.size !== "bigint" && typeof position !== "bigint") {
148
+ size = stats.size - position;
149
+ }
150
+ else {
151
+ size = BigInt(stats.size) - BigInt(position);
152
+ }
305
153
  }
306
- });
307
- });
308
- }
309
- static async rm(path, options) {
310
- return new Promise((resolve, reject) => {
311
- fs.rm(path, options, err => {
312
- if (err) {
313
- return reject(err);
154
+ if (size < 0n) {
155
+ return Buffer.alloc(0);
314
156
  }
315
- return resolve(undefined);
316
- });
317
- });
318
- }
157
+ const buffer = Buffer.alloc(Number(size));
158
+ return new Promise((resolve, reject) => {
159
+ fs.open(filePath, (err, file) => {
160
+ if (err) {
161
+ reject(err);
162
+ return;
163
+ }
164
+ fs.read(file, buffer, 0, buffer.length, position, (err, bytesRead, buffer) => {
165
+ if (err) {
166
+ reject(err);
167
+ return;
168
+ }
169
+ resolve(buffer);
170
+ });
171
+ });
172
+ });
173
+ }
174
+ static async readFile(filePath) {
175
+ return new Promise((resolve, reject) => {
176
+ fs.readFile(filePath, (err, data) => {
177
+ if (!err) {
178
+ resolve(data);
179
+ }
180
+ else {
181
+ reject(err);
182
+ }
183
+ });
184
+ });
185
+ }
186
+ static readFileSync(filePath) {
187
+ return fs.readFileSync(filePath);
188
+ }
189
+ static async writeFile(filePath, data, options) {
190
+ return new Promise((resolve, reject) => {
191
+ fs.writeFile(filePath, data, options, (err) => {
192
+ if (!err) {
193
+ resolve();
194
+ }
195
+ else {
196
+ reject(err);
197
+ }
198
+ });
199
+ });
200
+ }
201
+ static writeFileSync(path, data, options) {
202
+ return fs.writeFileSync(path, data, options);
203
+ }
204
+ static createWriteStream(path) {
205
+ return fs.createWriteStream(path);
206
+ }
207
+ static async readJSON(...paths) {
208
+ const res = await new Promise((resolve, reject) => {
209
+ const filePath = Path.join(...paths);
210
+ fs.readFile(filePath, (err, data) => {
211
+ if (err) {
212
+ reject(err);
213
+ return;
214
+ }
215
+ resolve(data);
216
+ });
217
+ });
218
+ return JSON.parse(res.toString());
219
+ }
220
+ static async writeJSON(filePath, data) {
221
+ const json = JSON.stringify(data, null, 4);
222
+ return FS.writeFile(filePath, json);
223
+ }
224
+ static async unlink(filePath) {
225
+ return new Promise((resolve, reject) => {
226
+ fs.unlink(filePath, (err) => {
227
+ if (!err) {
228
+ resolve();
229
+ }
230
+ else {
231
+ reject(err);
232
+ }
233
+ });
234
+ });
235
+ }
236
+ static watch(filename, options) {
237
+ return fs.watch(filename, options);
238
+ }
239
+ static stat(filename, options) {
240
+ return new Promise((resolve, reject) => {
241
+ fs.stat(filename, options, (err, stats) => {
242
+ if (err) {
243
+ reject(err);
244
+ }
245
+ else {
246
+ resolve(stats);
247
+ }
248
+ });
249
+ });
250
+ }
251
+ static createReadStream(path, options) {
252
+ return fs.createReadStream(path, options);
253
+ }
254
+ static createReadLinesStream(path, count) {
255
+ const write = new readable_stream_1.PassThrough();
256
+ (async () => {
257
+ if (typeof count === "undefined" || count > 0) {
258
+ const stats = await FS.stat(path);
259
+ const resLines = [""];
260
+ let position = 0n;
261
+ while (position < stats.size) {
262
+ let size = BigInt(count ? 64 * count : 255);
263
+ if (position + size > stats.size) {
264
+ size = BigInt(stats.size) - position;
265
+ }
266
+ const buffer = await FS.readBytes(path, position, size);
267
+ const lines = buffer.toString("utf-8").split("\n");
268
+ position += size;
269
+ for (let i = 0; i < lines.length; i++) {
270
+ const line = lines[i];
271
+ if (i === 0) {
272
+ resLines[resLines.length - 1] = (resLines[resLines.length - 1] || "") + line;
273
+ }
274
+ else {
275
+ resLines.push(line);
276
+ }
277
+ }
278
+ if (resLines.length > count + 1) {
279
+ break;
280
+ }
281
+ }
282
+ for (let i = 0; i < (count || resLines.length); i++) {
283
+ write.write(resLines[i]);
284
+ }
285
+ }
286
+ else if (count < 0) {
287
+ const stats = await FS.stat(path);
288
+ const resLines = [""];
289
+ let position = BigInt(stats.size);
290
+ while (position > 0n) {
291
+ let size = BigInt(2 * count * -1);
292
+ position -= size;
293
+ if (position < 0) {
294
+ size = position + size;
295
+ position = 0n;
296
+ }
297
+ const buffer = await FS.readBytes(path, position, size);
298
+ const lines = buffer.toString("utf-8").split("\n").reverse();
299
+ for (let i = 0; i < lines.length; i++) {
300
+ const line = lines[i];
301
+ if (i === 0) {
302
+ resLines[0] = line + (resLines[0] || "");
303
+ }
304
+ else {
305
+ resLines.unshift(line);
306
+ }
307
+ }
308
+ if (resLines.length > count * -1 + 1) {
309
+ break;
310
+ }
311
+ }
312
+ const lines = resLines.slice(count - 1);
313
+ for (let i = 0; i < lines.length; i++) {
314
+ write.write(lines[i]);
315
+ }
316
+ write.end();
317
+ }
318
+ })();
319
+ return write;
320
+ }
321
+ static async copyFile(src, dest) {
322
+ new Promise((resolve, reject) => {
323
+ fs.copyFile(src, dest, (err) => {
324
+ if (!err) {
325
+ resolve(undefined);
326
+ }
327
+ else {
328
+ reject(err);
329
+ }
330
+ });
331
+ });
332
+ }
333
+ static async rm(path, options) {
334
+ return new Promise((resolve, reject) => {
335
+ fs.rm(path, options, (err) => {
336
+ if (err) {
337
+ return reject(err);
338
+ }
339
+ return resolve(undefined);
340
+ });
341
+ });
342
+ }
319
343
  }
320
- exports.FS = FS;
344
+ exports.FS = FS;