soda-nodejs 0.1.2 → 0.1.4
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/README.md +23 -23
- package/dist/cjs/utils/unzip.d.ts +13 -5
- package/dist/cjs/utils/unzip.js +14 -8
- package/dist/cjs/utils/unzip.js.map +3 -3
- package/dist/cjs/utils/zip.d.ts +15 -4
- package/dist/cjs/utils/zip.js +16 -11
- package/dist/cjs/utils/zip.js.map +3 -3
- package/dist/esm/utils/unzip.d.ts +13 -5
- package/dist/esm/utils/unzip.js +14 -10
- package/dist/esm/utils/unzip.js.map +1 -1
- package/dist/esm/utils/zip.d.ts +15 -4
- package/dist/esm/utils/zip.js +18 -12
- package/dist/esm/utils/zip.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/unzip.ts +16 -12
- package/src/utils/zip.ts +20 -14
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
# soda-node
|
|
2
|
-
|
|
3
|
-
[](https://npmjs.com/package/soda-node)
|
|
4
|
-
[](https://npmjs.com/package/soda-node)
|
|
5
|
-
|
|
6
|
-
## Install
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
$ pnpm install
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
$ npm run dev
|
|
14
|
-
$ npm run build
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Options
|
|
18
|
-
|
|
19
|
-
TODO
|
|
20
|
-
|
|
21
|
-
## LICENSE
|
|
22
|
-
|
|
23
|
-
MIT
|
|
1
|
+
# soda-node
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/soda-node)
|
|
4
|
+
[](https://npmjs.com/package/soda-node)
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
$ pnpm install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
$ npm run dev
|
|
14
|
+
$ npm run build
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Options
|
|
18
|
+
|
|
19
|
+
TODO
|
|
20
|
+
|
|
21
|
+
## LICENSE
|
|
22
|
+
|
|
23
|
+
MIT
|
|
@@ -2,13 +2,21 @@ export type UnzipOptions = {
|
|
|
2
2
|
/**
|
|
3
3
|
* 要解压的文件
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
input: string;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* 解压到的目标文件夹位置
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
output: string;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* 使用 7z 命令解压文件
|
|
13
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
14
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
15
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
16
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
17
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
18
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
19
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
20
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
13
21
|
*/
|
|
14
|
-
export declare function unzip({
|
|
22
|
+
export declare function unzip({ input, output }: UnzipOptions): Promise<import("./execAsync").ExecResult<string>>;
|
package/dist/cjs/utils/unzip.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/utils/unzip.ts
|
|
@@ -22,15 +32,11 @@ __export(unzip_exports, {
|
|
|
22
32
|
unzip: () => unzip
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(unzip_exports);
|
|
25
|
-
var
|
|
35
|
+
var import_which = __toESM(require("which"));
|
|
26
36
|
var import_execAsync = require("./execAsync");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
(0, import_install7zip.install7zip)();
|
|
31
|
-
throw new Error("检测不到 7z 命令");
|
|
32
|
-
}
|
|
33
|
-
return await (0, import_execAsync.execAsync)(`7z x ${source} -o${target}`);
|
|
37
|
+
async function unzip({ input, output }) {
|
|
38
|
+
await (0, import_which.default)("7z");
|
|
39
|
+
return await (0, import_execAsync.execAsync)(`7z x ${input} -o${output}`);
|
|
34
40
|
}
|
|
35
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
42
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/unzip.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import which from \"which\"\r\nimport { execAsync } from \"./execAsync\"\r\n\r\nexport type UnzipOptions = {\r\n /**\r\n * 要解压的文件\r\n */\r\n input: string\r\n /**\r\n * 解压到的目标文件夹位置\r\n */\r\n output: string\r\n}\r\n\r\n/**\r\n * 使用 7z 命令解压文件\r\n * - 如果没有安装 7z,请先安装 7z 后再执行\r\n * - 下载地址:https://www.7-zip.org/download.html\r\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\r\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\r\n * 2. 在系统变量中找到并选中 Path,点击编辑\r\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\r\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\r\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\r\n */\r\nexport async function unzip({ input, output }: UnzipOptions) {\r\n await which(\"7z\")\r\n return await execAsync(`7z x ${input} -o${output}`)\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,uBAA0B;AAwB1B,eAAsB,MAAM,EAAE,OAAO,OAAO,GAAiB;AACzD,YAAM,aAAAA,SAAM,IAAI;AAChB,SAAO,UAAM,4BAAU,QAAQ,WAAW,QAAQ;AACtD;",
|
|
6
|
+
"names": ["which"]
|
|
7
7
|
}
|
package/dist/cjs/utils/zip.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ export type ZipOptions = {
|
|
|
2
2
|
/**
|
|
3
3
|
* 要压缩的文件
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
input: string | string[];
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
output: string;
|
|
10
10
|
/**
|
|
11
11
|
* 线程数
|
|
12
12
|
*/
|
|
@@ -20,4 +20,15 @@ export type ZipOptions = {
|
|
|
20
20
|
*/
|
|
21
21
|
password?: string;
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* 使用 7z 命令压缩文件
|
|
25
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
26
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
27
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
28
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
29
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
30
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
31
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
32
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
33
|
+
*/
|
|
34
|
+
export declare function zip({ input, output, thread, level, password }: ZipOptions): Promise<import("./execAsync").ExecResult<string>>;
|
package/dist/cjs/utils/zip.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/utils/zip.ts
|
|
@@ -23,19 +33,14 @@ __export(zip_exports, {
|
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(zip_exports);
|
|
25
35
|
var import_os = require("os");
|
|
36
|
+
var import_which = __toESM(require("which"));
|
|
26
37
|
var import_execAsync = require("./execAsync");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!await (0, import_check7zip.check7zip)()) {
|
|
31
|
-
(0, import_install7zip.install7zip)();
|
|
32
|
-
throw new Error("检测不到 7z 命令");
|
|
33
|
-
}
|
|
34
|
-
source = Array.isArray(source) ? source.join(" ") : source;
|
|
35
|
-
const cpuCount = (0, import_os.cpus)().length;
|
|
38
|
+
async function zip({ input, output, thread = "auto", level, password }) {
|
|
39
|
+
await (0, import_which.default)("7z");
|
|
40
|
+
input = Array.isArray(input) ? input.join(" ") : input;
|
|
36
41
|
if (thread === "max")
|
|
37
|
-
thread =
|
|
38
|
-
return await (0, import_execAsync.execAsync)(`7z a ${
|
|
42
|
+
thread = (0, import_os.cpus)().length;
|
|
43
|
+
return await (0, import_execAsync.execAsync)(`7z a ${output} ${input} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`);
|
|
39
44
|
}
|
|
40
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
46
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/zip.ts"],
|
|
4
|
-
"sourcesContent": ["import { cpus } from \"os\"\r\nimport
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { cpus } from \"os\"\r\nimport which from \"which\"\r\nimport { execAsync } from \"./execAsync\"\r\n\r\nexport type ZipOptions = {\r\n /**\r\n * 要压缩的文件\r\n */\r\n input: string | string[]\r\n /**\r\n * 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z\r\n */\r\n output: string\r\n /**\r\n * 线程数\r\n */\r\n thread?: number | \"auto\" | \"max\"\r\n /**\r\n * 压缩等级,0-9\r\n */\r\n level?: number\r\n /**\r\n * 是否加密\r\n */\r\n password?: string\r\n}\r\n\r\n/**\r\n * 使用 7z 命令压缩文件\r\n * - 如果没有安装 7z,请先安装 7z 后再执行\r\n * - 下载地址:https://www.7-zip.org/download.html\r\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\r\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\r\n * 2. 在系统变量中找到并选中 Path,点击编辑\r\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\r\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\r\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\r\n */\r\nexport async function zip({ input, output, thread = \"auto\", level, password }: ZipOptions) {\r\n await which(\"7z\")\r\n input = Array.isArray(input) ? input.join(\" \") : input\r\n if (thread === \"max\") thread = cpus().length\r\n return await execAsync(`7z a ${output} ${input} -mmt=${thread === \"auto\" ? \"on\" : thread}${typeof level === \"number\" ? ` -mx=${level}` : \"\"}${password ? ` -p${password}` : \"\"}`)\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqB;AACrB,mBAAkB;AAClB,uBAA0B;AAoC1B,eAAsB,IAAI,EAAE,OAAO,QAAQ,SAAS,QAAQ,OAAO,SAAS,GAAe;AACvF,YAAM,aAAAA,SAAM,IAAI;AAChB,UAAQ,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,GAAG,IAAI;AACjD,MAAI,WAAW;AAAO,iBAAS,gBAAK,EAAE;AACtC,SAAO,UAAM,4BAAU,QAAQ,UAAU,cAAc,WAAW,SAAS,OAAO,SAAS,OAAO,UAAU,WAAW,QAAQ,UAAU,KAAK,WAAW,MAAM,aAAa,IAAI;AACpL;",
|
|
6
|
+
"names": ["which"]
|
|
7
7
|
}
|
|
@@ -2,13 +2,21 @@ export type UnzipOptions = {
|
|
|
2
2
|
/**
|
|
3
3
|
* 要解压的文件
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
input: string;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* 解压到的目标文件夹位置
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
output: string;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* 使用 7z 命令解压文件
|
|
13
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
14
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
15
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
16
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
17
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
18
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
19
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
20
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
13
21
|
*/
|
|
14
|
-
export declare function unzip({
|
|
22
|
+
export declare function unzip({ input, output }: UnzipOptions): Promise<import("./execAsync").ExecResult<string>>;
|
package/dist/esm/utils/unzip.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import which from "which";
|
|
2
2
|
import { execAsync } from "./execAsync";
|
|
3
|
-
import { install7zip } from "./install7zip";
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* 使用 7z 命令解压文件
|
|
5
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
6
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
7
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
8
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
9
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
10
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
11
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
12
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
6
13
|
*/
|
|
7
14
|
export async function unzip({
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
input,
|
|
16
|
+
output
|
|
10
17
|
}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new Error("检测不到 7z 命令");
|
|
14
|
-
}
|
|
15
|
-
return await execAsync(`7z x ${source} -o${target}`);
|
|
18
|
+
await which("7z");
|
|
19
|
+
return await execAsync(`7z x ${input} -o${output}`);
|
|
16
20
|
}
|
|
17
21
|
//# sourceMappingURL=unzip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["which","execAsync","unzip","input","output"],"sources":["../../../src/utils/unzip.ts"],"sourcesContent":["import which from \"which\"\r\nimport { execAsync } from \"./execAsync\"\r\n\r\nexport type UnzipOptions = {\r\n /**\r\n * 要解压的文件\r\n */\r\n input: string\r\n /**\r\n * 解压到的目标文件夹位置\r\n */\r\n output: string\r\n}\r\n\r\n/**\r\n * 使用 7z 命令解压文件\r\n * - 如果没有安装 7z,请先安装 7z 后再执行\r\n * - 下载地址:https://www.7-zip.org/download.html\r\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\r\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\r\n * 2. 在系统变量中找到并选中 Path,点击编辑\r\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\r\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\r\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\r\n */\r\nexport async function unzip({ input, output }: UnzipOptions) {\r\n await which(\"7z\")\r\n return await execAsync(`7z x ${input} -o${output}`)\r\n}\r\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS;AAalB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,KAAKA,CAAC;EAAEC,KAAK;EAAEC;AAAqB,CAAC,EAAE;EACzD,MAAMJ,KAAK,CAAC,IAAI,CAAC;EACjB,OAAO,MAAMC,SAAS,CAAE,QAAOE,KAAM,MAAKC,MAAO,EAAC,CAAC;AACvD"}
|
package/dist/esm/utils/zip.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ export type ZipOptions = {
|
|
|
2
2
|
/**
|
|
3
3
|
* 要压缩的文件
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
input: string | string[];
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
output: string;
|
|
10
10
|
/**
|
|
11
11
|
* 线程数
|
|
12
12
|
*/
|
|
@@ -20,4 +20,15 @@ export type ZipOptions = {
|
|
|
20
20
|
*/
|
|
21
21
|
password?: string;
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* 使用 7z 命令压缩文件
|
|
25
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
26
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
27
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
28
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
29
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
30
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
31
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
32
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
33
|
+
*/
|
|
34
|
+
export declare function zip({ input, output, thread, level, password }: ZipOptions): Promise<import("./execAsync").ExecResult<string>>;
|
package/dist/esm/utils/zip.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import { cpus } from "os";
|
|
2
|
+
import which from "which";
|
|
2
3
|
import { execAsync } from "./execAsync";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* 使用 7z 命令压缩文件
|
|
6
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
7
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
8
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
9
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
10
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
11
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
12
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
13
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
14
|
+
*/
|
|
5
15
|
export async function zip({
|
|
6
|
-
|
|
7
|
-
|
|
16
|
+
input,
|
|
17
|
+
output,
|
|
8
18
|
thread = "auto",
|
|
9
19
|
level,
|
|
10
20
|
password
|
|
11
21
|
}) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
source = Array.isArray(source) ? source.join(" ") : source;
|
|
17
|
-
const cpuCount = cpus().length;
|
|
18
|
-
if (thread === "max") thread = cpuCount;
|
|
19
|
-
return await execAsync(`7z a ${target} ${source} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`);
|
|
22
|
+
await which("7z");
|
|
23
|
+
input = Array.isArray(input) ? input.join(" ") : input;
|
|
24
|
+
if (thread === "max") thread = cpus().length;
|
|
25
|
+
return await execAsync(`7z a ${output} ${input} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`);
|
|
20
26
|
}
|
|
21
27
|
//# sourceMappingURL=zip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["cpus","
|
|
1
|
+
{"version":3,"names":["cpus","which","execAsync","zip","input","output","thread","level","password","Array","isArray","join","length"],"sources":["../../../src/utils/zip.ts"],"sourcesContent":["import { cpus } from \"os\"\r\nimport which from \"which\"\r\nimport { execAsync } from \"./execAsync\"\r\n\r\nexport type ZipOptions = {\r\n /**\r\n * 要压缩的文件\r\n */\r\n input: string | string[]\r\n /**\r\n * 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z\r\n */\r\n output: string\r\n /**\r\n * 线程数\r\n */\r\n thread?: number | \"auto\" | \"max\"\r\n /**\r\n * 压缩等级,0-9\r\n */\r\n level?: number\r\n /**\r\n * 是否加密\r\n */\r\n password?: string\r\n}\r\n\r\n/**\r\n * 使用 7z 命令压缩文件\r\n * - 如果没有安装 7z,请先安装 7z 后再执行\r\n * - 下载地址:https://www.7-zip.org/download.html\r\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\r\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\r\n * 2. 在系统变量中找到并选中 Path,点击编辑\r\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\r\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\r\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\r\n */\r\nexport async function zip({ input, output, thread = \"auto\", level, password }: ZipOptions) {\r\n await which(\"7z\")\r\n input = Array.isArray(input) ? input.join(\" \") : input\r\n if (thread === \"max\") thread = cpus().length\r\n return await execAsync(`7z a ${output} ${input} -mmt=${thread === \"auto\" ? \"on\" : thread}${typeof level === \"number\" ? ` -mx=${level}` : \"\"}${password ? ` -p${password}` : \"\"}`)\r\n}\r\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,IAAI;AACzB,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS;AAyBlB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,GAAGA,CAAC;EAAEC,KAAK;EAAEC,MAAM;EAAEC,MAAM,GAAG,MAAM;EAAEC,KAAK;EAAEC;AAAqB,CAAC,EAAE;EACvF,MAAMP,KAAK,CAAC,IAAI,CAAC;EACjBG,KAAK,GAAGK,KAAK,CAACC,OAAO,CAACN,KAAK,CAAC,GAAGA,KAAK,CAACO,IAAI,CAAC,GAAG,CAAC,GAAGP,KAAK;EACtD,IAAIE,MAAM,KAAK,KAAK,EAAEA,MAAM,GAAGN,IAAI,CAAC,CAAC,CAACY,MAAM;EAC5C,OAAO,MAAMV,SAAS,CAAE,QAAOG,MAAO,IAAGD,KAAM,SAAQE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAGA,MAAO,GAAE,OAAOC,KAAK,KAAK,QAAQ,GAAI,QAAOA,KAAM,EAAC,GAAG,EAAG,GAAEC,QAAQ,GAAI,MAAKA,QAAS,EAAC,GAAG,EAAG,EAAC,CAAC;AACrL"}
|
package/package.json
CHANGED
package/src/utils/unzip.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import which from "which"
|
|
2
2
|
import { execAsync } from "./execAsync"
|
|
3
|
-
import { install7zip } from "./install7zip"
|
|
4
3
|
|
|
5
4
|
export type UnzipOptions = {
|
|
6
5
|
/**
|
|
7
6
|
* 要解压的文件
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
input: string
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
10
|
+
* 解压到的目标文件夹位置
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
output: string
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
16
|
+
* 使用 7z 命令解压文件
|
|
17
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
18
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
19
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
20
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
21
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
22
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
23
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
24
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
18
25
|
*/
|
|
19
|
-
export async function unzip({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
throw new Error("检测不到 7z 命令")
|
|
23
|
-
}
|
|
24
|
-
return await execAsync(`7z x ${source} -o${target}`)
|
|
26
|
+
export async function unzip({ input, output }: UnzipOptions) {
|
|
27
|
+
await which("7z")
|
|
28
|
+
return await execAsync(`7z x ${input} -o${output}`)
|
|
25
29
|
}
|
package/src/utils/zip.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { cpus } from "os"
|
|
2
|
+
import which from "which"
|
|
2
3
|
import { execAsync } from "./execAsync"
|
|
3
|
-
import { check7zip } from "./check7zip"
|
|
4
|
-
import { install7zip } from "./install7zip"
|
|
5
4
|
|
|
6
5
|
export type ZipOptions = {
|
|
7
6
|
/**
|
|
8
7
|
* 要压缩的文件
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
input: string | string[]
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
11
|
+
* 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z
|
|
13
12
|
*/
|
|
14
|
-
|
|
13
|
+
output: string
|
|
15
14
|
/**
|
|
16
15
|
* 线程数
|
|
17
16
|
*/
|
|
@@ -26,13 +25,20 @@ export type ZipOptions = {
|
|
|
26
25
|
password?: string
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
/**
|
|
29
|
+
* 使用 7z 命令压缩文件
|
|
30
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
31
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
32
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
33
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
34
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
35
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
36
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
37
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
38
|
+
*/
|
|
39
|
+
export async function zip({ input, output, thread = "auto", level, password }: ZipOptions) {
|
|
40
|
+
await which("7z")
|
|
41
|
+
input = Array.isArray(input) ? input.join(" ") : input
|
|
42
|
+
if (thread === "max") thread = cpus().length
|
|
43
|
+
return await execAsync(`7z a ${output} ${input} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`)
|
|
38
44
|
}
|