@maiyunnet/kebab 2.0.0

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 (114) hide show
  1. package/.VSCodeCounter/2025-02-14_14-46-44/details.md +82 -0
  2. package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +15 -0
  3. package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +2 -0
  4. package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +19 -0
  5. package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +22 -0
  6. package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +69 -0
  7. package/.VSCodeCounter/2025-02-14_14-46-44/results.json +1 -0
  8. package/.VSCodeCounter/2025-02-14_14-46-44/results.md +48 -0
  9. package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +118 -0
  10. package/.vscode/tasks.json +15 -0
  11. package/LICENSE +201 -0
  12. package/README.md +201 -0
  13. package/bin/kebab.js +2 -0
  14. package/eslint.config.js +22 -0
  15. package/index.js +19 -0
  16. package/index.ts +33 -0
  17. package/lib/buffer.js +108 -0
  18. package/lib/buffer.ts +152 -0
  19. package/lib/captcha/zcool-addict-italic.ttf +0 -0
  20. package/lib/captcha.js +71 -0
  21. package/lib/captcha.ts +63 -0
  22. package/lib/consistent.js +171 -0
  23. package/lib/consistent.ts +219 -0
  24. package/lib/core.js +663 -0
  25. package/lib/core.ts +880 -0
  26. package/lib/crypto.js +256 -0
  27. package/lib/crypto.ts +384 -0
  28. package/lib/db.js +521 -0
  29. package/lib/db.ts +719 -0
  30. package/lib/dns.js +321 -0
  31. package/lib/dns.ts +405 -0
  32. package/lib/fs.js +405 -0
  33. package/lib/fs.ts +527 -0
  34. package/lib/jwt.js +223 -0
  35. package/lib/jwt.ts +276 -0
  36. package/lib/kv.js +1004 -0
  37. package/lib/kv.ts +1489 -0
  38. package/lib/lan.js +99 -0
  39. package/lib/lan.ts +87 -0
  40. package/lib/net/cacert.pem +3480 -0
  41. package/lib/net/formdata.js +137 -0
  42. package/lib/net/formdata.ts +166 -0
  43. package/lib/net/request.js +102 -0
  44. package/lib/net/request.ts +150 -0
  45. package/lib/net/response.js +28 -0
  46. package/lib/net/response.ts +59 -0
  47. package/lib/net.js +462 -0
  48. package/lib/net.ts +662 -0
  49. package/lib/s3.js +180 -0
  50. package/lib/s3.ts +235 -0
  51. package/lib/scan.js +276 -0
  52. package/lib/scan.ts +364 -0
  53. package/lib/session.js +177 -0
  54. package/lib/session.ts +230 -0
  55. package/lib/sql.js +818 -0
  56. package/lib/sql.ts +1151 -0
  57. package/lib/ssh/sftp.js +373 -0
  58. package/lib/ssh/sftp.ts +508 -0
  59. package/lib/ssh/shell.js +109 -0
  60. package/lib/ssh/shell.ts +123 -0
  61. package/lib/ssh.js +171 -0
  62. package/lib/ssh.ts +191 -0
  63. package/lib/text/tld.json +1 -0
  64. package/lib/text.js +452 -0
  65. package/lib/text.ts +607 -0
  66. package/lib/time.js +216 -0
  67. package/lib/time.ts +254 -0
  68. package/lib/ws.js +373 -0
  69. package/lib/ws.ts +523 -0
  70. package/lib/zip.js +381 -0
  71. package/lib/zip.ts +447 -0
  72. package/lib/zlib.js +289 -0
  73. package/lib/zlib.ts +350 -0
  74. package/main.js +51 -0
  75. package/main.ts +27 -0
  76. package/package.json +37 -0
  77. package/sys/child.js +585 -0
  78. package/sys/child.ts +678 -0
  79. package/sys/cmd.js +226 -0
  80. package/sys/cmd.ts +225 -0
  81. package/sys/ctr.js +608 -0
  82. package/sys/ctr.ts +904 -0
  83. package/sys/master.js +314 -0
  84. package/sys/master.ts +355 -0
  85. package/sys/mod.js +1273 -0
  86. package/sys/mod.ts +1871 -0
  87. package/sys/route.js +922 -0
  88. package/sys/route.ts +1113 -0
  89. package/types/index.d.ts +283 -0
  90. package/www/example/ctr/main.js +42 -0
  91. package/www/example/ctr/main.ts +9 -0
  92. package/www/example/ctr/middle.js +57 -0
  93. package/www/example/ctr/middle.ts +26 -0
  94. package/www/example/ctr/test.js +2818 -0
  95. package/www/example/ctr/test.ts +3218 -0
  96. package/www/example/data/locale/en.test.json +8 -0
  97. package/www/example/data/locale/index.html +1 -0
  98. package/www/example/data/locale/ja.test.json +8 -0
  99. package/www/example/data/locale/sc.test.json +8 -0
  100. package/www/example/data/locale/tc.test.json +8 -0
  101. package/www/example/data/test.zip +0 -0
  102. package/www/example/kebab.json +24 -0
  103. package/www/example/mod/test.js +49 -0
  104. package/www/example/mod/test.ts +47 -0
  105. package/www/example/mod/testdata.js +11 -0
  106. package/www/example/mod/testdata.ts +30 -0
  107. package/www/example/route.json +6 -0
  108. package/www/example/view/test.ejs +11 -0
  109. package/www/example/ws/mproxy.js +49 -0
  110. package/www/example/ws/mproxy.ts +16 -0
  111. package/www/example/ws/rproxy.js +47 -0
  112. package/www/example/ws/rproxy.ts +14 -0
  113. package/www/example/ws/test.js +68 -0
  114. package/www/example/ws/test.ts +36 -0
package/lib/zlib.js ADDED
@@ -0,0 +1,289 @@
1
+ "use strict";
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;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createGzip = createGzip;
37
+ exports.createGunzip = createGunzip;
38
+ exports.createDeflate = createDeflate;
39
+ exports.createInflate = createInflate;
40
+ exports.createBrotliCompress = createBrotliCompress;
41
+ exports.createBrotliDecompress = createBrotliDecompress;
42
+ exports.createCompress = createCompress;
43
+ exports.createDecompress = createDecompress;
44
+ exports.gzip = gzip;
45
+ exports.gunzip = gunzip;
46
+ exports.deflate = deflate;
47
+ exports.inflate = inflate;
48
+ exports.brotliCompress = brotliCompress;
49
+ exports.brotliDecompress = brotliDecompress;
50
+ exports.compress = compress;
51
+ exports.decompress = decompress;
52
+ const zlib = __importStar(require("zlib"));
53
+ function createGzip(options = {}) {
54
+ if (!options.level) {
55
+ options.level = 7;
56
+ }
57
+ return zlib.createGzip(options);
58
+ }
59
+ function createGunzip() {
60
+ return zlib.createGunzip();
61
+ }
62
+ function createDeflate(options = {}) {
63
+ if (!options.level) {
64
+ options.level = 7;
65
+ }
66
+ return zlib.createDeflate(options);
67
+ }
68
+ function createInflate() {
69
+ return zlib.createInflate();
70
+ }
71
+ function createBrotliCompress(options = {}) {
72
+ if (!options.level) {
73
+ options.level = 7;
74
+ }
75
+ return zlib.createBrotliCompress(options);
76
+ }
77
+ function createBrotliDecompress() {
78
+ return zlib.createBrotliDecompress();
79
+ }
80
+ function createCompress(types, options = {}) {
81
+ if (!options.level) {
82
+ options.level = 7;
83
+ }
84
+ const type = getTypeByTypes(types);
85
+ if (!type) {
86
+ return null;
87
+ }
88
+ switch (type) {
89
+ case 'gzip': {
90
+ return {
91
+ 'type': 'gzip',
92
+ 'compress': zlib.createGzip(options)
93
+ };
94
+ }
95
+ case 'deflate': {
96
+ return {
97
+ 'type': 'deflate',
98
+ 'compress': zlib.createDeflate(options)
99
+ };
100
+ }
101
+ case 'br': {
102
+ return {
103
+ 'type': 'br',
104
+ 'compress': zlib.createBrotliCompress(options)
105
+ };
106
+ }
107
+ }
108
+ return null;
109
+ }
110
+ function createDecompress(types) {
111
+ const type = getTypeByTypes(types);
112
+ if (!type) {
113
+ return null;
114
+ }
115
+ switch (type) {
116
+ case 'gzip': {
117
+ return {
118
+ 'type': 'gzip',
119
+ 'compress': zlib.createGunzip()
120
+ };
121
+ }
122
+ case 'deflate': {
123
+ return {
124
+ 'type': 'deflate',
125
+ 'compress': zlib.createInflate()
126
+ };
127
+ }
128
+ case 'br': {
129
+ return {
130
+ 'type': 'br',
131
+ 'compress': zlib.createBrotliDecompress()
132
+ };
133
+ }
134
+ }
135
+ return null;
136
+ }
137
+ function gzip(buffer, options = {}) {
138
+ if (!options.level) {
139
+ options.level = 7;
140
+ }
141
+ return new Promise(function (resolve) {
142
+ zlib.gzip(buffer, options, function (error, result) {
143
+ if (error) {
144
+ resolve(null);
145
+ }
146
+ else {
147
+ resolve(result);
148
+ }
149
+ });
150
+ });
151
+ }
152
+ function gunzip(buffer) {
153
+ return new Promise(function (resolve) {
154
+ zlib.gunzip(buffer, function (error, result) {
155
+ if (error) {
156
+ resolve(null);
157
+ }
158
+ else {
159
+ resolve(result);
160
+ }
161
+ });
162
+ });
163
+ }
164
+ function deflate(buffer, options = {}) {
165
+ if (!options.level) {
166
+ options.level = 7;
167
+ }
168
+ return new Promise(function (resolve) {
169
+ zlib.deflate(buffer, options, function (error, result) {
170
+ if (error) {
171
+ resolve(null);
172
+ }
173
+ else {
174
+ resolve(result);
175
+ }
176
+ });
177
+ });
178
+ }
179
+ function inflate(buffer) {
180
+ return new Promise(function (resolve) {
181
+ zlib.inflate(buffer, function (error, result) {
182
+ if (error) {
183
+ resolve(null);
184
+ }
185
+ else {
186
+ resolve(result);
187
+ }
188
+ });
189
+ });
190
+ }
191
+ function brotliCompress(buffer, options = {}) {
192
+ if (!options.level) {
193
+ options.level = 7;
194
+ }
195
+ return new Promise(function (resolve) {
196
+ zlib.brotliCompress(buffer, options, function (error, result) {
197
+ if (error) {
198
+ resolve(null);
199
+ }
200
+ else {
201
+ resolve(result);
202
+ }
203
+ });
204
+ });
205
+ }
206
+ function brotliDecompress(buffer) {
207
+ return new Promise(function (resolve) {
208
+ zlib.brotliDecompress(buffer, function (error, result) {
209
+ if (error) {
210
+ resolve(null);
211
+ }
212
+ else {
213
+ resolve(result);
214
+ }
215
+ });
216
+ });
217
+ }
218
+ async function compress(types, buffer, options) {
219
+ if (!buffer) {
220
+ return null;
221
+ }
222
+ const type = getTypeByTypes(types);
223
+ if (!type) {
224
+ return null;
225
+ }
226
+ let outBuffer = null;
227
+ switch (type) {
228
+ case 'gzip': {
229
+ outBuffer = await gzip(buffer, options);
230
+ break;
231
+ }
232
+ case 'deflate': {
233
+ outBuffer = await deflate(buffer, options);
234
+ break;
235
+ }
236
+ case 'br': {
237
+ outBuffer = await brotliCompress(buffer, options);
238
+ break;
239
+ }
240
+ }
241
+ if (!outBuffer) {
242
+ return null;
243
+ }
244
+ return {
245
+ 'type': type,
246
+ 'buffer': outBuffer
247
+ };
248
+ }
249
+ async function decompress(types, buffer) {
250
+ if (!buffer) {
251
+ return null;
252
+ }
253
+ const type = getTypeByTypes(types);
254
+ if (!type) {
255
+ return null;
256
+ }
257
+ let outBuffer = null;
258
+ switch (type) {
259
+ case 'gzip': {
260
+ outBuffer = await gunzip(buffer);
261
+ break;
262
+ }
263
+ case 'deflate': {
264
+ outBuffer = await inflate(buffer);
265
+ break;
266
+ }
267
+ case 'br': {
268
+ outBuffer = await brotliDecompress(buffer);
269
+ break;
270
+ }
271
+ }
272
+ if (!outBuffer) {
273
+ return null;
274
+ }
275
+ return {
276
+ 'type': type,
277
+ 'buffer': outBuffer
278
+ };
279
+ }
280
+ function getTypeByTypes(types) {
281
+ const typesArray = types.split(',');
282
+ for (let type of typesArray) {
283
+ type = type.trim().toLowerCase();
284
+ if (['gzip', 'deflate', 'br'].includes(type)) {
285
+ return type;
286
+ }
287
+ }
288
+ return null;
289
+ }
package/lib/zlib.ts ADDED
@@ -0,0 +1,350 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2019-4-9 16:00:55
4
+ * Last: 2020-03-20 14:45:47, 2022-09-13 13:43:32
5
+ */
6
+ import * as zlib from 'zlib';
7
+
8
+ /** 某个压缩对象 */
9
+ export interface ICompress {
10
+ readonly type: string;
11
+ readonly compress: zlib.Deflate |
12
+ zlib.Gzip | zlib.BrotliCompress | zlib.Inflate | zlib.Gunzip | zlib.BrotliDecompress;
13
+ }
14
+
15
+ /** 某个压缩后的变量 */
16
+ export interface ICompressBuffer {
17
+ readonly type: string;
18
+ readonly buffer: Buffer;
19
+ }
20
+
21
+ /**
22
+ * --- 创建 Gzip 对象 ---
23
+ * @param options 选项
24
+ */
25
+ export function createGzip(options: zlib.ZlibOptions = {}): zlib.Gzip {
26
+ if (!options.level) {
27
+ options.level = 7;
28
+ }
29
+ return zlib.createGzip(options);
30
+ }
31
+
32
+ /**
33
+ * --- 创建 Gzip 解压对象 ---
34
+ */
35
+ export function createGunzip(): zlib.Gunzip {
36
+ return zlib.createGunzip();
37
+ }
38
+
39
+ /**
40
+ * --- 创建 Deflate 对象 ---
41
+ * @param options 选项
42
+ */
43
+ export function createDeflate(options: zlib.ZlibOptions = {}): zlib.Deflate {
44
+ if (!options.level) {
45
+ options.level = 7;
46
+ }
47
+ return zlib.createDeflate(options);
48
+ }
49
+
50
+ /**
51
+ * --- 创建 Deflate 解压对象 ---
52
+ */
53
+ export function createInflate(): zlib.Inflate {
54
+ return zlib.createInflate();
55
+ }
56
+
57
+ /**
58
+ * --- 创建 Brotli 压缩对象 ---
59
+ * @param options 选项
60
+ */
61
+ export function createBrotliCompress(options: zlib.ZlibOptions = {}): zlib.BrotliCompress {
62
+ if (!options.level) {
63
+ options.level = 7;
64
+ }
65
+ return zlib.createBrotliCompress(options);
66
+ }
67
+
68
+ /**
69
+ * --- 创建 Brotli 解压对象 ---
70
+ */
71
+ export function createBrotliDecompress(): zlib.BrotliDecompress {
72
+ return zlib.createBrotliDecompress();
73
+ }
74
+
75
+ /**
76
+ * --- 根据字符串创建压缩类型 ---
77
+ * @param types 用 , 间隔的字符串,如 gzip,deflate
78
+ * @param options 选项
79
+ */
80
+ export function createCompress(types: string, options: zlib.ZlibOptions = {}): ICompress | null {
81
+ if (!options.level) {
82
+ options.level = 7;
83
+ }
84
+ const type = getTypeByTypes(types);
85
+ if (!type) {
86
+ return null;
87
+ }
88
+ switch (type) {
89
+ case 'gzip': {
90
+ return {
91
+ 'type': 'gzip',
92
+ 'compress': zlib.createGzip(options)
93
+ };
94
+ }
95
+ case 'deflate': {
96
+ return {
97
+ 'type': 'deflate',
98
+ 'compress': zlib.createDeflate(options)
99
+ };
100
+ }
101
+ case 'br': {
102
+ return {
103
+ 'type': 'br',
104
+ 'compress': zlib.createBrotliCompress(options)
105
+ };
106
+ }
107
+ }
108
+ return null;
109
+ }
110
+
111
+ /**
112
+ * --- 根据字符串创建解压类型 ---
113
+ * @param types 用 , 间隔的字符串,如 gzip,deflate
114
+ * @param options 选项
115
+ */
116
+ export function createDecompress(types: string): ICompress | null {
117
+ const type = getTypeByTypes(types);
118
+ if (!type) {
119
+ return null;
120
+ }
121
+ switch (type) {
122
+ case 'gzip': {
123
+ return {
124
+ 'type': 'gzip',
125
+ 'compress': zlib.createGunzip()
126
+ };
127
+ }
128
+ case 'deflate': {
129
+ return {
130
+ 'type': 'deflate',
131
+ 'compress': zlib.createInflate()
132
+ };
133
+ }
134
+ case 'br': {
135
+ return {
136
+ 'type': 'br',
137
+ 'compress': zlib.createBrotliDecompress()
138
+ };
139
+ }
140
+ }
141
+ return null;
142
+ }
143
+
144
+ /**
145
+ * Gzip 压缩一段
146
+ * @param buffer 段
147
+ * @param options 选项
148
+ */
149
+ export function gzip(buffer: zlib.InputType, options: zlib.ZlibOptions = {}): Promise<Buffer | null> {
150
+ if (!options.level) {
151
+ options.level = 7;
152
+ }
153
+ return new Promise(function(resolve) {
154
+ zlib.gzip(buffer, options, function(error: Error | null, result: Buffer) {
155
+ if (error) {
156
+ resolve(null);
157
+ }
158
+ else {
159
+ resolve(result);
160
+ }
161
+ });
162
+ });
163
+ }
164
+
165
+ /**
166
+ * Gzip 解压一段
167
+ * @param buffer 段
168
+ */
169
+ export function gunzip(buffer: zlib.InputType): Promise<Buffer | null> {
170
+ return new Promise(function(resolve) {
171
+ zlib.gunzip(buffer, function(error: Error | null, result: Buffer) {
172
+ if (error) {
173
+ resolve(null);
174
+ }
175
+ else {
176
+ resolve(result);
177
+ }
178
+ });
179
+ });
180
+ }
181
+
182
+ /**
183
+ * Deflate 压缩一段
184
+ * @param buffer 段
185
+ * @param options 选项
186
+ */
187
+ export function deflate(buffer: zlib.InputType, options: zlib.ZlibOptions = {}): Promise<Buffer | null> {
188
+ if (!options.level) {
189
+ options.level = 7;
190
+ }
191
+ return new Promise(function(resolve) {
192
+ zlib.deflate(buffer, options, function(error: Error | null, result: Buffer) {
193
+ if (error) {
194
+ resolve(null);
195
+ }
196
+ else {
197
+ resolve(result);
198
+ }
199
+ });
200
+ });
201
+ }
202
+
203
+ /**
204
+ * Deflate 解压一段
205
+ * @param buffer 段
206
+ */
207
+ export function inflate(buffer: zlib.InputType): Promise<Buffer | null> {
208
+ return new Promise(function(resolve) {
209
+ zlib.inflate(buffer, function(error: Error | null, result: Buffer) {
210
+ if (error) {
211
+ resolve(null);
212
+ }
213
+ else {
214
+ resolve(result);
215
+ }
216
+ });
217
+ });
218
+ }
219
+
220
+ /**
221
+ * Brotli 压缩一段
222
+ * @param buffer 段
223
+ * @param options 选项
224
+ */
225
+ export function brotliCompress(buffer: zlib.InputType, options: zlib.ZlibOptions = {}): Promise<Buffer | null> {
226
+ if (!options.level) {
227
+ options.level = 7;
228
+ }
229
+ return new Promise(function(resolve) {
230
+ zlib.brotliCompress(buffer, options, function(error: Error | null, result: Buffer) {
231
+ if (error) {
232
+ resolve(null);
233
+ }
234
+ else {
235
+ resolve(result);
236
+ }
237
+ });
238
+ });
239
+ }
240
+
241
+ /**
242
+ * Brotli 解压一段
243
+ * @param buffer 段
244
+ */
245
+ export function brotliDecompress(buffer: zlib.InputType): Promise<Buffer | null> {
246
+ return new Promise(function(resolve) {
247
+ zlib.brotliDecompress(buffer, function(error: Error | null, result: Buffer) {
248
+ if (error) {
249
+ resolve(null);
250
+ }
251
+ else {
252
+ resolve(result);
253
+ }
254
+ });
255
+ });
256
+ }
257
+
258
+ /**
259
+ * --- 根据 types 判断用什么加密的段 ---
260
+ * @param types 用,间隔的字符串,如 gzip,deflate
261
+ * @param buffer 段
262
+ * @param options 选项
263
+ */
264
+ export async function compress(
265
+ types: string,
266
+ buffer: zlib.InputType | null,
267
+ options?: zlib.ZlibOptions
268
+ ): Promise<ICompressBuffer | null> {
269
+ if (!buffer) {
270
+ return null;
271
+ }
272
+ const type = getTypeByTypes(types);
273
+ if (!type) {
274
+ return null;
275
+ }
276
+ let outBuffer: Buffer | null = null;
277
+ switch (type) {
278
+ case 'gzip': {
279
+ outBuffer = await gzip(buffer, options);
280
+ break;
281
+ }
282
+ case 'deflate': {
283
+ outBuffer = await deflate(buffer, options);
284
+ break;
285
+ }
286
+ case 'br': {
287
+ outBuffer = await brotliCompress(buffer, options);
288
+ break;
289
+ }
290
+ }
291
+ if (!outBuffer) {
292
+ return null;
293
+ }
294
+ return {
295
+ 'type': type,
296
+ 'buffer': outBuffer
297
+ };
298
+ }
299
+
300
+ /**
301
+ * --- 根据 types 判断用什么解密的段 ---
302
+ * @param types 用,间隔的字符串,如 gzip,deflate
303
+ * @param buffer 段
304
+ */
305
+ export async function decompress(types: string, buffer: zlib.InputType | null): Promise<ICompressBuffer | null> {
306
+ if (!buffer) {
307
+ return null;
308
+ }
309
+ const type = getTypeByTypes(types);
310
+ if (!type) {
311
+ return null;
312
+ }
313
+ let outBuffer: Buffer | null = null;
314
+ switch (type) {
315
+ case 'gzip': {
316
+ outBuffer = await gunzip(buffer);
317
+ break;
318
+ }
319
+ case 'deflate': {
320
+ outBuffer = await inflate(buffer);
321
+ break;
322
+ }
323
+ case 'br': {
324
+ outBuffer = await brotliDecompress(buffer);
325
+ break;
326
+ }
327
+ }
328
+ if (!outBuffer) {
329
+ return null;
330
+ }
331
+ return {
332
+ 'type': type,
333
+ 'buffer': outBuffer
334
+ };
335
+ }
336
+
337
+ /**
338
+ * --- 根据 types 字符串获取优先 type
339
+ * @param types types 字符串
340
+ */
341
+ function getTypeByTypes(types: string): string| null {
342
+ const typesArray = types.split(',');
343
+ for (let type of typesArray) {
344
+ type = type.trim().toLowerCase();
345
+ if (['gzip', 'deflate', 'br'].includes(type)) {
346
+ return type;
347
+ }
348
+ }
349
+ return null;
350
+ }
package/main.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
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;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const cluster_1 = __importDefault(require("cluster"));
40
+ require("ts-alias-loader");
41
+ if (cluster_1.default.isPrimary) {
42
+ if (process.argv.length > 2) {
43
+ Promise.resolve().then(() => __importStar(require('./sys/cmd')));
44
+ }
45
+ else {
46
+ Promise.resolve().then(() => __importStar(require('./sys/master')));
47
+ }
48
+ }
49
+ else {
50
+ Promise.resolve().then(() => __importStar(require('./sys/child')));
51
+ }
package/main.ts ADDED
@@ -0,0 +1,27 @@
1
+ /* eslint-disable @typescript-eslint/no-floating-promises */
2
+ /**
3
+ * Project: Kebab, User: JianSuoQiYue
4
+ * Date: 2019-3-29 18:55:35
5
+ * Last: 2020-3-6 22:19:37, 2022-3-30 01:01:22, 2022-9-27 16:11:40, 2025-6-13 12:56:18
6
+ */
7
+ // git config core.ignorecase false
8
+
9
+ import cluster from 'cluster';
10
+ // --- 第三方 ---
11
+ import 'ts-alias-loader';
12
+
13
+ // --- 初始化 ---
14
+ // --- 一定要分别隔离加载 Master 和 Child 代码,防止执行串了 ---
15
+ if (cluster.isPrimary) {
16
+ if (process.argv.length > 2) {
17
+ // --- 传入的命令方式启动,则执行 RPC 相关命令 ---
18
+ import('./sys/cmd');
19
+ }
20
+ else {
21
+ // --- 正常启动 ---
22
+ import('./sys/master');
23
+ }
24
+ }
25
+ else {
26
+ import('./sys/child');
27
+ }