@maiyunnet/kebab 2.0.7 → 2.0.9
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.
- package/index.d.ts +11 -1
- package/index.js +13 -1
- package/lib/buffer.d.ts +25 -0
- package/lib/buffer.js +30 -5
- package/lib/captcha.d.ts +15 -0
- package/lib/captcha.js +20 -0
- package/lib/consistent.d.ts +51 -0
- package/lib/consistent.js +59 -0
- package/lib/core.d.ts +134 -0
- package/lib/core.js +176 -0
- package/lib/crypto.d.ts +75 -6
- package/lib/crypto.js +206 -38
- package/lib/db.d.ts +104 -0
- package/lib/db.js +126 -0
- package/lib/dns.d.ts +51 -0
- package/lib/dns.js +54 -2
- package/lib/fs.d.ts +100 -0
- package/lib/fs.js +118 -0
- package/lib/jwt.d.ts +43 -0
- package/lib/jwt.js +45 -0
- package/lib/kv.d.ts +362 -0
- package/lib/kv.js +377 -0
- package/lib/lan.d.ts +6 -0
- package/lib/lan.js +7 -0
- package/lib/net/formdata.d.ts +38 -0
- package/lib/net/formdata.js +43 -0
- package/lib/net/request.d.ts +62 -0
- package/lib/net/request.js +57 -0
- package/lib/net/response.d.ts +21 -0
- package/lib/net/response.js +16 -0
- package/lib/net.d.ts +86 -0
- package/lib/net.js +140 -0
- package/lib/s3.d.ts +52 -0
- package/lib/s3.js +51 -0
- package/lib/scan.d.ts +52 -0
- package/lib/scan.js +84 -0
- package/lib/session.d.ts +31 -0
- package/lib/session.js +52 -1
- package/lib/sql.d.ts +176 -0
- package/lib/sql.js +287 -2
- package/lib/ssh/sftp.d.ts +106 -0
- package/lib/ssh/sftp.js +106 -0
- package/lib/ssh/shell.d.ts +37 -0
- package/lib/ssh/shell.js +31 -0
- package/lib/ssh.d.ts +32 -0
- package/lib/ssh.js +32 -0
- package/lib/text.d.ts +131 -0
- package/lib/text.js +188 -0
- package/lib/time.d.ts +53 -0
- package/lib/time.js +55 -0
- package/lib/ws.d.ts +68 -0
- package/lib/ws.js +74 -0
- package/lib/zip.d.ts +53 -0
- package/lib/zip.js +73 -0
- package/lib/zlib.d.ts +76 -0
- package/lib/zlib.js +78 -0
- package/main.d.ts +5 -0
- package/main.js +12 -0
- package/package.json +3 -2
- package/sys/child.js +104 -0
- package/sys/cmd.js +28 -0
- package/sys/ctr.d.ts +166 -0
- package/sys/ctr.js +177 -0
- package/sys/master.js +63 -0
- package/sys/mod.d.ts +266 -0
- package/sys/mod.js +335 -0
- package/sys/route.d.ts +34 -0
- package/sys/route.js +164 -0
- package/www/example/ctr/test.d.ts +3 -0
- package/www/example/ctr/test.js +63 -1
- package/www/example/mod/test.js +14 -0
- package/www/example/mod/testdata.js +9 -0
- package/www/example/ws/test.js +1 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/details.md +0 -82
- package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +0 -15
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +0 -2
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +0 -19
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +0 -22
- package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +0 -69
- package/.VSCodeCounter/2025-02-14_14-46-44/results.json +0 -1
- package/.VSCodeCounter/2025-02-14_14-46-44/results.md +0 -48
- package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +0 -118
- package/.vscode/tasks.json +0 -15
package/lib/zip.js
CHANGED
|
@@ -41,13 +41,23 @@ exports.get = get;
|
|
|
41
41
|
const jszip_1 = __importDefault(require("jszip"));
|
|
42
42
|
const mime = __importStar(require("@litert/mime"));
|
|
43
43
|
const lText = __importStar(require("../lib/text"));
|
|
44
|
+
/**
|
|
45
|
+
* --- 本库主要用于读取 zip,请尽量不要用来写入 zip,尤其是大文件 zip ---
|
|
46
|
+
*/
|
|
44
47
|
class Zip {
|
|
45
48
|
constructor(zip) {
|
|
49
|
+
/** --- 当前路径,以 / 开头以 / 结尾 --- */
|
|
46
50
|
this._path = '/';
|
|
51
|
+
/** --- 目录列表缓存 --- */
|
|
47
52
|
this._list = {};
|
|
48
53
|
this._zip = zip;
|
|
49
54
|
this._refreshList();
|
|
50
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* --- 读取完整文件 ---
|
|
58
|
+
* @param path 文件路径
|
|
59
|
+
* @param type 返回类型
|
|
60
|
+
*/
|
|
51
61
|
async getContent(path, type = 'string') {
|
|
52
62
|
path = lText.urlResolve(this._path, path);
|
|
53
63
|
const f = this._zip.file(path.slice(1));
|
|
@@ -61,6 +71,12 @@ class Zip {
|
|
|
61
71
|
return f.async(type);
|
|
62
72
|
}
|
|
63
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* --- 写入文件内容 ---
|
|
76
|
+
* @param path 文件路径
|
|
77
|
+
* @param data 要写入的内容
|
|
78
|
+
* @param options 选项
|
|
79
|
+
*/
|
|
64
80
|
putContent(path, data, options = {}) {
|
|
65
81
|
path = lText.urlResolve(this._path, path);
|
|
66
82
|
this._zip.file(path.slice(1), data, {
|
|
@@ -70,22 +86,34 @@ class Zip {
|
|
|
70
86
|
});
|
|
71
87
|
this._refreshList();
|
|
72
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* --- 删除一个文件/文件夹(深度删除) ---
|
|
91
|
+
* @param path 要删除的文件路径
|
|
92
|
+
*/
|
|
73
93
|
unlink(path) {
|
|
74
94
|
path = lText.urlResolve(this._path, path);
|
|
75
95
|
this._zip.remove(path.slice(1));
|
|
76
96
|
this._refreshList();
|
|
77
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* --- 获取对象是否存在,存在则返回 stats 对象,否则返回 null ---
|
|
100
|
+
* @param path 对象路径
|
|
101
|
+
* @param options 选项
|
|
102
|
+
*/
|
|
78
103
|
stats(path) {
|
|
79
104
|
path = lText.urlResolve(this._path, path);
|
|
80
105
|
let dirpath = path.endsWith('/') ? path : path + '/';
|
|
81
106
|
if (!this._list[dirpath]) {
|
|
107
|
+
// --- 可能是文件 ---
|
|
82
108
|
if (path.endsWith('/')) {
|
|
109
|
+
// --- 不可能是文件 ---
|
|
83
110
|
return null;
|
|
84
111
|
}
|
|
85
112
|
const lio = path.lastIndexOf('/') + 1;
|
|
86
113
|
const dpath = path.slice(0, lio);
|
|
87
114
|
const fname = path.slice(lio);
|
|
88
115
|
if (!this._list[dpath]) {
|
|
116
|
+
// --- 上层目录不存在 ---
|
|
89
117
|
return null;
|
|
90
118
|
}
|
|
91
119
|
const file = this._list[dpath][fname];
|
|
@@ -101,6 +129,7 @@ class Zip {
|
|
|
101
129
|
};
|
|
102
130
|
}
|
|
103
131
|
else {
|
|
132
|
+
// --- 文件夹 ---
|
|
104
133
|
if (dirpath === '/') {
|
|
105
134
|
return {
|
|
106
135
|
'compressedSize': 0,
|
|
@@ -125,6 +154,10 @@ class Zip {
|
|
|
125
154
|
};
|
|
126
155
|
}
|
|
127
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* --- 判断是否是目录或目录是否存在,是的话返回 stats ---
|
|
159
|
+
* @param path 判断路径
|
|
160
|
+
*/
|
|
128
161
|
isDir(path) {
|
|
129
162
|
const pstats = this.stats(path);
|
|
130
163
|
if (!pstats?.isDirectory) {
|
|
@@ -132,6 +165,10 @@ class Zip {
|
|
|
132
165
|
}
|
|
133
166
|
return pstats;
|
|
134
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* --- 判断是否是文件或文件是否存在,是的话返回 stats ---
|
|
170
|
+
* @param path 判断路径
|
|
171
|
+
*/
|
|
135
172
|
isFile(path) {
|
|
136
173
|
const pstats = this.stats(path);
|
|
137
174
|
if (!pstats?.isFile) {
|
|
@@ -139,6 +176,11 @@ class Zip {
|
|
|
139
176
|
}
|
|
140
177
|
return pstats;
|
|
141
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* --- 获取文件夹下文件列表 ---
|
|
181
|
+
* @param path 文件夹路径
|
|
182
|
+
* @param opt 选项
|
|
183
|
+
*/
|
|
142
184
|
readDir(path, opt = {}) {
|
|
143
185
|
if (opt.hasChildren === undefined) {
|
|
144
186
|
opt.hasChildren = false;
|
|
@@ -175,8 +217,10 @@ class Zip {
|
|
|
175
217
|
}
|
|
176
218
|
return list;
|
|
177
219
|
}
|
|
220
|
+
// --- 定义 list ---
|
|
178
221
|
if (opt.pathAsKey) {
|
|
179
222
|
const list = {};
|
|
223
|
+
// --- 遍历子项 ---
|
|
180
224
|
for (const k in this._list[path]) {
|
|
181
225
|
const item = this._list[path][k];
|
|
182
226
|
if (item.isFile || opt.hasDir) {
|
|
@@ -193,6 +237,7 @@ class Zip {
|
|
|
193
237
|
}
|
|
194
238
|
else {
|
|
195
239
|
let list = [];
|
|
240
|
+
// --- 遍历子项 ---
|
|
196
241
|
for (const k in this._list[path]) {
|
|
197
242
|
const item = this._list[path][k];
|
|
198
243
|
if (item.isFile || opt.hasDir) {
|
|
@@ -208,6 +253,10 @@ class Zip {
|
|
|
208
253
|
return list;
|
|
209
254
|
}
|
|
210
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* --- 根据 item 文件夹读取子层及所有子层项 ---
|
|
258
|
+
* @param item 文件夹
|
|
259
|
+
*/
|
|
211
260
|
_readDir(item, opt) {
|
|
212
261
|
if (opt.pathAsKey) {
|
|
213
262
|
const list = {};
|
|
@@ -248,8 +297,12 @@ class Zip {
|
|
|
248
297
|
return list;
|
|
249
298
|
}
|
|
250
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* --- 重建目录列表缓存 ---
|
|
302
|
+
*/
|
|
251
303
|
_refreshList() {
|
|
252
304
|
const list = {};
|
|
305
|
+
// eslint-disable-next-line @litert/rules/disable-for-each-method
|
|
253
306
|
this._zip.forEach(function (relativePath, item) {
|
|
254
307
|
if (relativePath.startsWith('/')) {
|
|
255
308
|
relativePath = relativePath.slice(1);
|
|
@@ -288,9 +341,18 @@ class Zip {
|
|
|
288
341
|
});
|
|
289
342
|
this._list = list;
|
|
290
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* --- 获取当前目录,末尾不带 / ---
|
|
346
|
+
* @return string
|
|
347
|
+
*/
|
|
291
348
|
pwd() {
|
|
292
349
|
return this._path.slice(0, -1);
|
|
293
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* --- 进入一个目录(不存在也能进入,需要自行判断) ---
|
|
353
|
+
* --- 返回进入后的路径值 ---
|
|
354
|
+
* @param dir 相对路径或绝对路径
|
|
355
|
+
*/
|
|
294
356
|
cd(dir) {
|
|
295
357
|
this._path = lText.urlResolve(this._path, dir);
|
|
296
358
|
if (!this._path.endsWith('/')) {
|
|
@@ -298,6 +360,10 @@ class Zip {
|
|
|
298
360
|
}
|
|
299
361
|
return this._path;
|
|
300
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* --- 打包 zip ---
|
|
365
|
+
* @param options 选项
|
|
366
|
+
*/
|
|
301
367
|
generate(options = {}) {
|
|
302
368
|
const opt = {};
|
|
303
369
|
if (options.type === undefined) {
|
|
@@ -319,6 +385,9 @@ class Zip {
|
|
|
319
385
|
options.onUpdate?.(meta.percent, meta.currentFile);
|
|
320
386
|
});
|
|
321
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* --- 获取 path 和 string/Buffer 对应的文件列表 ---
|
|
390
|
+
*/
|
|
322
391
|
getList() {
|
|
323
392
|
return new Promise((resolve) => {
|
|
324
393
|
const files = {};
|
|
@@ -367,6 +436,10 @@ class Zip {
|
|
|
367
436
|
}
|
|
368
437
|
}
|
|
369
438
|
exports.Zip = Zip;
|
|
439
|
+
/**
|
|
440
|
+
* --- 获取 zip 对象 ---
|
|
441
|
+
* @param data 对象数据
|
|
442
|
+
*/
|
|
370
443
|
async function get(data) {
|
|
371
444
|
const z = (0, jszip_1.default)();
|
|
372
445
|
try {
|
package/lib/zlib.d.ts
CHANGED
|
@@ -1,25 +1,101 @@
|
|
|
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
|
+
*/
|
|
1
6
|
import * as zlib from 'zlib';
|
|
7
|
+
/** 某个压缩对象 */
|
|
2
8
|
export interface ICompress {
|
|
3
9
|
readonly type: string;
|
|
4
10
|
readonly compress: zlib.Deflate | zlib.Gzip | zlib.BrotliCompress | zlib.Inflate | zlib.Gunzip | zlib.BrotliDecompress;
|
|
5
11
|
}
|
|
12
|
+
/** 某个压缩后的变量 */
|
|
6
13
|
export interface ICompressBuffer {
|
|
7
14
|
readonly type: string;
|
|
8
15
|
readonly buffer: Buffer;
|
|
9
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* --- 创建 Gzip 对象 ---
|
|
19
|
+
* @param options 选项
|
|
20
|
+
*/
|
|
10
21
|
export declare function createGzip(options?: zlib.ZlibOptions): zlib.Gzip;
|
|
22
|
+
/**
|
|
23
|
+
* --- 创建 Gzip 解压对象 ---
|
|
24
|
+
*/
|
|
11
25
|
export declare function createGunzip(): zlib.Gunzip;
|
|
26
|
+
/**
|
|
27
|
+
* --- 创建 Deflate 对象 ---
|
|
28
|
+
* @param options 选项
|
|
29
|
+
*/
|
|
12
30
|
export declare function createDeflate(options?: zlib.ZlibOptions): zlib.Deflate;
|
|
31
|
+
/**
|
|
32
|
+
* --- 创建 Deflate 解压对象 ---
|
|
33
|
+
*/
|
|
13
34
|
export declare function createInflate(): zlib.Inflate;
|
|
35
|
+
/**
|
|
36
|
+
* --- 创建 Brotli 压缩对象 ---
|
|
37
|
+
* @param options 选项
|
|
38
|
+
*/
|
|
14
39
|
export declare function createBrotliCompress(options?: zlib.ZlibOptions): zlib.BrotliCompress;
|
|
40
|
+
/**
|
|
41
|
+
* --- 创建 Brotli 解压对象 ---
|
|
42
|
+
*/
|
|
15
43
|
export declare function createBrotliDecompress(): zlib.BrotliDecompress;
|
|
44
|
+
/**
|
|
45
|
+
* --- 根据字符串创建压缩类型 ---
|
|
46
|
+
* @param types 用 , 间隔的字符串,如 gzip,deflate
|
|
47
|
+
* @param options 选项
|
|
48
|
+
*/
|
|
16
49
|
export declare function createCompress(types: string, options?: zlib.ZlibOptions): ICompress | null;
|
|
50
|
+
/**
|
|
51
|
+
* --- 根据字符串创建解压类型 ---
|
|
52
|
+
* @param types 用 , 间隔的字符串,如 gzip,deflate
|
|
53
|
+
* @param options 选项
|
|
54
|
+
*/
|
|
17
55
|
export declare function createDecompress(types: string): ICompress | null;
|
|
56
|
+
/**
|
|
57
|
+
* Gzip 压缩一段
|
|
58
|
+
* @param buffer 段
|
|
59
|
+
* @param options 选项
|
|
60
|
+
*/
|
|
18
61
|
export declare function gzip(buffer: zlib.InputType, options?: zlib.ZlibOptions): Promise<Buffer | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Gzip 解压一段
|
|
64
|
+
* @param buffer 段
|
|
65
|
+
*/
|
|
19
66
|
export declare function gunzip(buffer: zlib.InputType): Promise<Buffer | null>;
|
|
67
|
+
/**
|
|
68
|
+
* Deflate 压缩一段
|
|
69
|
+
* @param buffer 段
|
|
70
|
+
* @param options 选项
|
|
71
|
+
*/
|
|
20
72
|
export declare function deflate(buffer: zlib.InputType, options?: zlib.ZlibOptions): Promise<Buffer | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Deflate 解压一段
|
|
75
|
+
* @param buffer 段
|
|
76
|
+
*/
|
|
21
77
|
export declare function inflate(buffer: zlib.InputType): Promise<Buffer | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Brotli 压缩一段
|
|
80
|
+
* @param buffer 段
|
|
81
|
+
* @param options 选项
|
|
82
|
+
*/
|
|
22
83
|
export declare function brotliCompress(buffer: zlib.InputType, options?: zlib.ZlibOptions): Promise<Buffer | null>;
|
|
84
|
+
/**
|
|
85
|
+
* Brotli 解压一段
|
|
86
|
+
* @param buffer 段
|
|
87
|
+
*/
|
|
23
88
|
export declare function brotliDecompress(buffer: zlib.InputType): Promise<Buffer | null>;
|
|
89
|
+
/**
|
|
90
|
+
* --- 根据 types 判断用什么加密的段 ---
|
|
91
|
+
* @param types 用,间隔的字符串,如 gzip,deflate
|
|
92
|
+
* @param buffer 段
|
|
93
|
+
* @param options 选项
|
|
94
|
+
*/
|
|
24
95
|
export declare function compress(types: string, buffer: zlib.InputType | null, options?: zlib.ZlibOptions): Promise<ICompressBuffer | null>;
|
|
96
|
+
/**
|
|
97
|
+
* --- 根据 types 判断用什么解密的段 ---
|
|
98
|
+
* @param types 用,间隔的字符串,如 gzip,deflate
|
|
99
|
+
* @param buffer 段
|
|
100
|
+
*/
|
|
25
101
|
export declare function decompress(types: string, buffer: zlib.InputType | null): Promise<ICompressBuffer | null>;
|
package/lib/zlib.js
CHANGED
|
@@ -49,34 +49,65 @@ exports.brotliCompress = brotliCompress;
|
|
|
49
49
|
exports.brotliDecompress = brotliDecompress;
|
|
50
50
|
exports.compress = compress;
|
|
51
51
|
exports.decompress = decompress;
|
|
52
|
+
/**
|
|
53
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
54
|
+
* Date: 2019-4-9 16:00:55
|
|
55
|
+
* Last: 2020-03-20 14:45:47, 2022-09-13 13:43:32
|
|
56
|
+
*/
|
|
52
57
|
const zlib = __importStar(require("zlib"));
|
|
58
|
+
/**
|
|
59
|
+
* --- 创建 Gzip 对象 ---
|
|
60
|
+
* @param options 选项
|
|
61
|
+
*/
|
|
53
62
|
function createGzip(options = {}) {
|
|
54
63
|
if (!options.level) {
|
|
55
64
|
options.level = 7;
|
|
56
65
|
}
|
|
57
66
|
return zlib.createGzip(options);
|
|
58
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* --- 创建 Gzip 解压对象 ---
|
|
70
|
+
*/
|
|
59
71
|
function createGunzip() {
|
|
60
72
|
return zlib.createGunzip();
|
|
61
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* --- 创建 Deflate 对象 ---
|
|
76
|
+
* @param options 选项
|
|
77
|
+
*/
|
|
62
78
|
function createDeflate(options = {}) {
|
|
63
79
|
if (!options.level) {
|
|
64
80
|
options.level = 7;
|
|
65
81
|
}
|
|
66
82
|
return zlib.createDeflate(options);
|
|
67
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* --- 创建 Deflate 解压对象 ---
|
|
86
|
+
*/
|
|
68
87
|
function createInflate() {
|
|
69
88
|
return zlib.createInflate();
|
|
70
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* --- 创建 Brotli 压缩对象 ---
|
|
92
|
+
* @param options 选项
|
|
93
|
+
*/
|
|
71
94
|
function createBrotliCompress(options = {}) {
|
|
72
95
|
if (!options.level) {
|
|
73
96
|
options.level = 7;
|
|
74
97
|
}
|
|
75
98
|
return zlib.createBrotliCompress(options);
|
|
76
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* --- 创建 Brotli 解压对象 ---
|
|
102
|
+
*/
|
|
77
103
|
function createBrotliDecompress() {
|
|
78
104
|
return zlib.createBrotliDecompress();
|
|
79
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* --- 根据字符串创建压缩类型 ---
|
|
108
|
+
* @param types 用 , 间隔的字符串,如 gzip,deflate
|
|
109
|
+
* @param options 选项
|
|
110
|
+
*/
|
|
80
111
|
function createCompress(types, options = {}) {
|
|
81
112
|
if (!options.level) {
|
|
82
113
|
options.level = 7;
|
|
@@ -107,6 +138,11 @@ function createCompress(types, options = {}) {
|
|
|
107
138
|
}
|
|
108
139
|
return null;
|
|
109
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* --- 根据字符串创建解压类型 ---
|
|
143
|
+
* @param types 用 , 间隔的字符串,如 gzip,deflate
|
|
144
|
+
* @param options 选项
|
|
145
|
+
*/
|
|
110
146
|
function createDecompress(types) {
|
|
111
147
|
const type = getTypeByTypes(types);
|
|
112
148
|
if (!type) {
|
|
@@ -134,6 +170,11 @@ function createDecompress(types) {
|
|
|
134
170
|
}
|
|
135
171
|
return null;
|
|
136
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Gzip 压缩一段
|
|
175
|
+
* @param buffer 段
|
|
176
|
+
* @param options 选项
|
|
177
|
+
*/
|
|
137
178
|
function gzip(buffer, options = {}) {
|
|
138
179
|
if (!options.level) {
|
|
139
180
|
options.level = 7;
|
|
@@ -149,6 +190,10 @@ function gzip(buffer, options = {}) {
|
|
|
149
190
|
});
|
|
150
191
|
});
|
|
151
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Gzip 解压一段
|
|
195
|
+
* @param buffer 段
|
|
196
|
+
*/
|
|
152
197
|
function gunzip(buffer) {
|
|
153
198
|
return new Promise(function (resolve) {
|
|
154
199
|
zlib.gunzip(buffer, function (error, result) {
|
|
@@ -161,6 +206,11 @@ function gunzip(buffer) {
|
|
|
161
206
|
});
|
|
162
207
|
});
|
|
163
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Deflate 压缩一段
|
|
211
|
+
* @param buffer 段
|
|
212
|
+
* @param options 选项
|
|
213
|
+
*/
|
|
164
214
|
function deflate(buffer, options = {}) {
|
|
165
215
|
if (!options.level) {
|
|
166
216
|
options.level = 7;
|
|
@@ -176,6 +226,10 @@ function deflate(buffer, options = {}) {
|
|
|
176
226
|
});
|
|
177
227
|
});
|
|
178
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Deflate 解压一段
|
|
231
|
+
* @param buffer 段
|
|
232
|
+
*/
|
|
179
233
|
function inflate(buffer) {
|
|
180
234
|
return new Promise(function (resolve) {
|
|
181
235
|
zlib.inflate(buffer, function (error, result) {
|
|
@@ -188,6 +242,11 @@ function inflate(buffer) {
|
|
|
188
242
|
});
|
|
189
243
|
});
|
|
190
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Brotli 压缩一段
|
|
247
|
+
* @param buffer 段
|
|
248
|
+
* @param options 选项
|
|
249
|
+
*/
|
|
191
250
|
function brotliCompress(buffer, options = {}) {
|
|
192
251
|
if (!options.level) {
|
|
193
252
|
options.level = 7;
|
|
@@ -203,6 +262,10 @@ function brotliCompress(buffer, options = {}) {
|
|
|
203
262
|
});
|
|
204
263
|
});
|
|
205
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Brotli 解压一段
|
|
267
|
+
* @param buffer 段
|
|
268
|
+
*/
|
|
206
269
|
function brotliDecompress(buffer) {
|
|
207
270
|
return new Promise(function (resolve) {
|
|
208
271
|
zlib.brotliDecompress(buffer, function (error, result) {
|
|
@@ -215,6 +278,12 @@ function brotliDecompress(buffer) {
|
|
|
215
278
|
});
|
|
216
279
|
});
|
|
217
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* --- 根据 types 判断用什么加密的段 ---
|
|
283
|
+
* @param types 用,间隔的字符串,如 gzip,deflate
|
|
284
|
+
* @param buffer 段
|
|
285
|
+
* @param options 选项
|
|
286
|
+
*/
|
|
218
287
|
async function compress(types, buffer, options) {
|
|
219
288
|
if (!buffer) {
|
|
220
289
|
return null;
|
|
@@ -246,6 +315,11 @@ async function compress(types, buffer, options) {
|
|
|
246
315
|
'buffer': outBuffer
|
|
247
316
|
};
|
|
248
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* --- 根据 types 判断用什么解密的段 ---
|
|
320
|
+
* @param types 用,间隔的字符串,如 gzip,deflate
|
|
321
|
+
* @param buffer 段
|
|
322
|
+
*/
|
|
249
323
|
async function decompress(types, buffer) {
|
|
250
324
|
if (!buffer) {
|
|
251
325
|
return null;
|
|
@@ -277,6 +351,10 @@ async function decompress(types, buffer) {
|
|
|
277
351
|
'buffer': outBuffer
|
|
278
352
|
};
|
|
279
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* --- 根据 types 字符串获取优先 type
|
|
356
|
+
* @param types types 字符串
|
|
357
|
+
*/
|
|
280
358
|
function getTypeByTypes(types) {
|
|
281
359
|
const typesArray = types.split(',');
|
|
282
360
|
for (let type of typesArray) {
|
package/main.d.ts
CHANGED
package/main.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-floating-promises */
|
|
3
|
+
/**
|
|
4
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
5
|
+
* Date: 2019-3-29 18:55:35
|
|
6
|
+
* 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
|
|
7
|
+
*/
|
|
8
|
+
// git config core.ignorecase false
|
|
2
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
10
|
if (k2 === undefined) k2 = k;
|
|
4
11
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -37,12 +44,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
44
|
};
|
|
38
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
46
|
const cluster_1 = __importDefault(require("cluster"));
|
|
47
|
+
// --- 虽然框架本身不用,但是业务侧会用到,所以这个库不能删 ---
|
|
40
48
|
require("ts-alias-loader");
|
|
49
|
+
// --- 初始化 ---
|
|
50
|
+
// --- 一定要分别隔离加载 Master 和 Child 代码,防止执行串了 ---
|
|
41
51
|
if (cluster_1.default.isPrimary) {
|
|
42
52
|
if (process.argv.length > 2) {
|
|
53
|
+
// --- 传入的命令方式启动,则执行 RPC 相关命令 ---
|
|
43
54
|
Promise.resolve().then(() => __importStar(require('./sys/cmd')));
|
|
44
55
|
}
|
|
45
56
|
else {
|
|
57
|
+
// --- 正常启动 ---
|
|
46
58
|
Promise.resolve().then(() => __importStar(require('./sys/master')));
|
|
47
59
|
}
|
|
48
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maiyunnet/kebab",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kebab",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"jszip": "^3.10.1",
|
|
26
26
|
"mysql2": "^3.14.1",
|
|
27
27
|
"ssh2": "^1.16.0",
|
|
28
|
-
"svg-captcha": "^1.4.0"
|
|
28
|
+
"svg-captcha": "^1.4.0",
|
|
29
|
+
"ts-alias-loader": "^0.1.5"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@litert/eslint-plugin-rules": "^0.3.1",
|