soda-nodejs 0.0.4 → 0.1.1
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/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +11 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/utils/check7zip.d.ts +4 -0
- package/dist/cjs/utils/check7zip.js +48 -0
- package/dist/cjs/utils/check7zip.js.map +7 -0
- package/dist/cjs/utils/install7zip.d.ts +4 -0
- package/dist/cjs/utils/install7zip.js +39 -0
- package/dist/cjs/utils/install7zip.js.map +7 -0
- package/dist/cjs/utils/saveFile.d.ts +10 -0
- package/dist/cjs/utils/saveFile.js +37 -0
- package/dist/cjs/utils/saveFile.js.map +7 -0
- package/dist/cjs/utils/unzip.d.ts +14 -0
- package/dist/cjs/utils/unzip.js +39 -0
- package/dist/cjs/utils/unzip.js.map +7 -0
- package/dist/cjs/utils/zip.d.ts +23 -0
- package/dist/cjs/utils/zip.js +44 -0
- package/dist/cjs/utils/zip.js.map +7 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/check7zip.d.ts +4 -0
- package/dist/esm/utils/check7zip.js +14 -0
- package/dist/esm/utils/check7zip.js.map +1 -0
- package/dist/esm/utils/install7zip.d.ts +4 -0
- package/dist/esm/utils/install7zip.js +14 -0
- package/dist/esm/utils/install7zip.js.map +1 -0
- package/dist/esm/utils/saveFile.d.ts +10 -0
- package/dist/esm/utils/saveFile.js +15 -0
- package/dist/esm/utils/saveFile.js.map +1 -0
- package/dist/esm/utils/unzip.d.ts +14 -0
- package/dist/esm/utils/unzip.js +17 -0
- package/dist/esm/utils/unzip.js.map +1 -0
- package/dist/esm/utils/zip.d.ts +23 -0
- package/dist/esm/utils/zip.js +21 -0
- package/dist/esm/utils/zip.js.map +1 -0
- package/package.json +5 -1
- package/src/index.ts +5 -0
- package/src/utils/check7zip.ts +13 -0
- package/src/utils/install7zip.ts +13 -0
- package/src/utils/saveFile.ts +22 -0
- package/src/utils/unzip.ts +25 -0
- package/src/utils/zip.ts +38 -0
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -16,11 +16,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
// src/index.ts
|
|
17
17
|
var src_exports = {};
|
|
18
18
|
module.exports = __toCommonJS(src_exports);
|
|
19
|
+
__reExport(src_exports, require("./utils/check7zip"), module.exports);
|
|
19
20
|
__reExport(src_exports, require("./utils/execAsync"), module.exports);
|
|
21
|
+
__reExport(src_exports, require("./utils/install7zip"), module.exports);
|
|
22
|
+
__reExport(src_exports, require("./utils/saveFile"), module.exports);
|
|
20
23
|
__reExport(src_exports, require("./utils/spawnAsync"), module.exports);
|
|
24
|
+
__reExport(src_exports, require("./utils/unzip"), module.exports);
|
|
25
|
+
__reExport(src_exports, require("./utils/zip"), module.exports);
|
|
21
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
27
|
0 && (module.exports = {
|
|
28
|
+
...require("./utils/check7zip"),
|
|
23
29
|
...require("./utils/execAsync"),
|
|
24
|
-
...require("./utils/
|
|
30
|
+
...require("./utils/install7zip"),
|
|
31
|
+
...require("./utils/saveFile"),
|
|
32
|
+
...require("./utils/spawnAsync"),
|
|
33
|
+
...require("./utils/unzip"),
|
|
34
|
+
...require("./utils/zip")
|
|
25
35
|
});
|
|
26
36
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from \"@utils/execAsync\"\nexport * from \"@utils/spawnAsync\"\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,8BAAd;AACA,wBAAc,+
|
|
4
|
+
"sourcesContent": ["export * from \"@utils/check7zip\"\nexport * from \"@utils/execAsync\"\nexport * from \"@utils/install7zip\"\nexport * from \"@utils/saveFile\"\nexport * from \"@utils/spawnAsync\"\nexport * from \"@utils/unzip\"\nexport * from \"@utils/zip\"\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,8BAAd;AACA,wBAAc,8BADd;AAEA,wBAAc,gCAFd;AAGA,wBAAc,6BAHd;AAIA,wBAAc,+BAJd;AAKA,wBAAc,0BALd;AAMA,wBAAc,wBANd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
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
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/utils/check7zip.ts
|
|
30
|
+
var check7zip_exports = {};
|
|
31
|
+
__export(check7zip_exports, {
|
|
32
|
+
check7zip: () => check7zip
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(check7zip_exports);
|
|
35
|
+
var import_which = __toESM(require("which"));
|
|
36
|
+
async function check7zip() {
|
|
37
|
+
try {
|
|
38
|
+
await (0, import_which.default)("7z");
|
|
39
|
+
return true;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
check7zip
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=check7zip.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/check7zip.ts"],
|
|
4
|
+
"sourcesContent": ["import which from \"which\"\r\n\r\n/**\r\n * 检测 7z 命令是否存在\r\n */\r\nexport async function check7zip() {\r\n try {\r\n await which(\"7z\")\r\n return true\r\n } catch (error) {\r\n return false\r\n }\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAKlB,eAAsB,YAAY;AAC9B,MAAI;AACA,cAAM,aAAAA,SAAM,IAAI;AAChB,WAAO;AAAA,EACX,SAAS,OAAP;AACE,WAAO;AAAA,EACX;AACJ;",
|
|
6
|
+
"names": ["which"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/install7zip.ts
|
|
20
|
+
var install7zip_exports = {};
|
|
21
|
+
__export(install7zip_exports, {
|
|
22
|
+
install7zip: () => install7zip
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(install7zip_exports);
|
|
25
|
+
function install7zip() {
|
|
26
|
+
console.log("检测到您的系统没有安装 7z,请先安装 7z 后再执行");
|
|
27
|
+
console.log("下载地址:https://www.7-zip.org/download.html");
|
|
28
|
+
console.log("如果已经安装,请按照以下步骤将 7z 添加到环境变量中");
|
|
29
|
+
console.log("1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量");
|
|
30
|
+
console.log("2. 在系统变量中找到并选中 Path,点击编辑");
|
|
31
|
+
console.log("3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定");
|
|
32
|
+
console.log("4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功");
|
|
33
|
+
console.log("5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确");
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
install7zip
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=install7zip.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/install7zip.ts"],
|
|
4
|
+
"sourcesContent": ["/**\r\n * 检测到没有安装 7z 时的提示信息\r\n */\r\nexport function install7zip() {\r\n console.log(\"检测到您的系统没有安装 7z,请先安装 7z 后再执行\")\r\n console.log(\"下载地址:https://www.7-zip.org/download.html\")\r\n console.log(\"如果已经安装,请按照以下步骤将 7z 添加到环境变量中\")\r\n console.log(\"1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\")\r\n console.log(\"2. 在系统变量中找到并选中 Path,点击编辑\")\r\n console.log(\"3. 点击新建,输入 7z 的安装路径(默认是 C:\\\\Program Files\\\\7-Zip),点击确定\")\r\n console.log(\"4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\")\r\n console.log(\"5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\")\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,cAAc;AAC1B,UAAQ,IAAI,6BAA6B;AACzC,UAAQ,IAAI,0CAA0C;AACtD,UAAQ,IAAI,6BAA6B;AACzC,UAAQ,IAAI,qCAAqC;AACjD,UAAQ,IAAI,0BAA0B;AACtC,UAAQ,IAAI,wDAAwD;AACpE,UAAQ,IAAI,mCAAmC;AAC/C,UAAQ,IAAI,uCAAuC;AACvD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/saveFile.ts
|
|
20
|
+
var saveFile_exports = {};
|
|
21
|
+
__export(saveFile_exports, {
|
|
22
|
+
saveFile: () => saveFile
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(saveFile_exports);
|
|
25
|
+
var import_fs = require("fs");
|
|
26
|
+
var import_stream = require("stream");
|
|
27
|
+
async function saveFile({ file, target }) {
|
|
28
|
+
await new Promise((resolve, reject) => {
|
|
29
|
+
const writeAble = (0, import_fs.createWriteStream)(target);
|
|
30
|
+
import_stream.Readable.fromWeb(file.stream()).pipe(writeAble).on("finish", resolve).on("error", reject);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
saveFile
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=saveFile.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/saveFile.ts"],
|
|
4
|
+
"sourcesContent": ["import { createWriteStream } from \"fs\"\r\nimport { Readable } from \"stream\"\r\n\r\nexport type SaveFileOptions = {\r\n /** 要保存的文件 */\r\n file: File\r\n /** 保存文件的目标位置 */\r\n target: string\r\n}\r\n\r\n/**\r\n * 保存文件\r\n */\r\nexport async function saveFile({ file, target }: SaveFileOptions) {\r\n await new Promise((resolve, reject) => {\r\n const writeAble = createWriteStream(target)\r\n Readable.fromWeb(file.stream() as any)\r\n .pipe(writeAble)\r\n .on(\"finish\", resolve)\r\n .on(\"error\", reject)\r\n })\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAkC;AAClC,oBAAyB;AAYzB,eAAsB,SAAS,EAAE,MAAM,OAAO,GAAoB;AAC9D,QAAM,IAAI,QAAQ,CAAC,SAAS,WAAW;AACnC,UAAM,gBAAY,6BAAkB,MAAM;AAC1C,2BAAS,QAAQ,KAAK,OAAO,CAAQ,EAChC,KAAK,SAAS,EACd,GAAG,UAAU,OAAO,EACpB,GAAG,SAAS,MAAM;AAAA,EAC3B,CAAC;AACL;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type UnzipOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* 要解压的文件
|
|
4
|
+
*/
|
|
5
|
+
source: string;
|
|
6
|
+
/**
|
|
7
|
+
* 解压到的目标位置
|
|
8
|
+
*/
|
|
9
|
+
target: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* 解压文件
|
|
13
|
+
*/
|
|
14
|
+
export declare function unzip({ source, target }: UnzipOptions): Promise<import("./execAsync").ExecResult<string> | undefined>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/unzip.ts
|
|
20
|
+
var unzip_exports = {};
|
|
21
|
+
__export(unzip_exports, {
|
|
22
|
+
unzip: () => unzip
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(unzip_exports);
|
|
25
|
+
var import_check7zip = require("./check7zip");
|
|
26
|
+
var import_execAsync = require("./execAsync");
|
|
27
|
+
var import_install7zip = require("./install7zip");
|
|
28
|
+
async function unzip({ source, target }) {
|
|
29
|
+
if (!await (0, import_check7zip.check7zip)()) {
|
|
30
|
+
(0, import_install7zip.install7zip)();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
return await (0, import_execAsync.execAsync)(`7z x ${source} -o${target}`);
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
unzip
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=unzip.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/unzip.ts"],
|
|
4
|
+
"sourcesContent": ["import { check7zip } from \"./check7zip\"\r\nimport { execAsync } from \"./execAsync\"\r\nimport { install7zip } from \"./install7zip\"\r\n\r\nexport type UnzipOptions = {\r\n /**\r\n * 要解压的文件\r\n */\r\n source: string\r\n /**\r\n * 解压到的目标位置\r\n */\r\n target: string\r\n}\r\n\r\n/**\r\n * 解压文件\r\n */\r\nexport async function unzip({ source, target }: UnzipOptions) {\r\n if (!(await check7zip())) {\r\n install7zip()\r\n return\r\n }\r\n return await execAsync(`7z x ${source} -o${target}`)\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA0B;AAC1B,uBAA0B;AAC1B,yBAA4B;AAgB5B,eAAsB,MAAM,EAAE,QAAQ,OAAO,GAAiB;AAC1D,MAAI,CAAE,UAAM,4BAAU,GAAI;AACtB,wCAAY;AACZ;AAAA,EACJ;AACA,SAAO,UAAM,4BAAU,QAAQ,YAAY,QAAQ;AACvD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ZipOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* 要压缩的文件
|
|
4
|
+
*/
|
|
5
|
+
source: string | string[];
|
|
6
|
+
/**
|
|
7
|
+
* 压缩到的目标位置
|
|
8
|
+
*/
|
|
9
|
+
target: string;
|
|
10
|
+
/**
|
|
11
|
+
* 线程数
|
|
12
|
+
*/
|
|
13
|
+
thread?: number | "auto" | "max";
|
|
14
|
+
/**
|
|
15
|
+
* 压缩等级,0-9
|
|
16
|
+
*/
|
|
17
|
+
level?: number;
|
|
18
|
+
/**
|
|
19
|
+
* 是否加密
|
|
20
|
+
*/
|
|
21
|
+
password?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function zip({ source, target, thread, level, password }: ZipOptions): Promise<import("./execAsync").ExecResult<string> | undefined>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/zip.ts
|
|
20
|
+
var zip_exports = {};
|
|
21
|
+
__export(zip_exports, {
|
|
22
|
+
zip: () => zip
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(zip_exports);
|
|
25
|
+
var import_os = require("os");
|
|
26
|
+
var import_execAsync = require("./execAsync");
|
|
27
|
+
var import_check7zip = require("./check7zip");
|
|
28
|
+
var import_install7zip = require("./install7zip");
|
|
29
|
+
async function zip({ source, target, thread = "auto", level, password }) {
|
|
30
|
+
if (!await (0, import_check7zip.check7zip)()) {
|
|
31
|
+
(0, import_install7zip.install7zip)();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
source = Array.isArray(source) ? source.join(" ") : source;
|
|
35
|
+
const cpuCount = (0, import_os.cpus)().length;
|
|
36
|
+
if (thread === "max")
|
|
37
|
+
thread = cpuCount;
|
|
38
|
+
return await (0, import_execAsync.execAsync)(`7z a ${target} ${source} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`);
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
zip
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=zip.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/zip.ts"],
|
|
4
|
+
"sourcesContent": ["import { cpus } from \"os\"\r\nimport { execAsync } from \"./execAsync\"\r\nimport { check7zip } from \"./check7zip\"\r\nimport { install7zip } from \"./install7zip\"\r\n\r\nexport type ZipOptions = {\r\n /**\r\n * 要压缩的文件\r\n */\r\n source: string | string[]\r\n /**\r\n * 压缩到的目标位置\r\n */\r\n target: 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\nexport async function zip({ source, target, thread = \"auto\", level, password }: ZipOptions) {\r\n if (!(await check7zip())) {\r\n install7zip()\r\n return\r\n }\r\n source = Array.isArray(source) ? source.join(\" \") : source\r\n const cpuCount = cpus().length\r\n if (thread === \"max\") thread = cpuCount\r\n return await execAsync(`7z a ${target} ${source} -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,uBAA0B;AAC1B,uBAA0B;AAC1B,yBAA4B;AAyB5B,eAAsB,IAAI,EAAE,QAAQ,QAAQ,SAAS,QAAQ,OAAO,SAAS,GAAe;AACxF,MAAI,CAAE,UAAM,4BAAU,GAAI;AACtB,wCAAY;AACZ;AAAA,EACJ;AACA,WAAS,MAAM,QAAQ,MAAM,IAAI,OAAO,KAAK,GAAG,IAAI;AACpD,QAAM,eAAW,gBAAK,EAAE;AACxB,MAAI,WAAW;AAAO,aAAS;AAC/B,SAAO,UAAM,4BAAU,QAAQ,UAAU,eAAe,WAAW,SAAS,OAAO,SAAS,OAAO,UAAU,WAAW,QAAQ,UAAU,KAAK,WAAW,MAAM,aAAa,IAAI;AACrL;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export * from "./utils/check7zip";
|
|
1
2
|
export * from "./utils/execAsync";
|
|
3
|
+
export * from "./utils/install7zip";
|
|
4
|
+
export * from "./utils/saveFile";
|
|
2
5
|
export * from "./utils/spawnAsync";
|
|
6
|
+
export * from "./utils/unzip";
|
|
7
|
+
export * from "./utils/zip";
|
|
3
8
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"@utils/execAsync\"\nexport * from \"@utils/spawnAsync\"\n"],"mappings":"AAAA;AACA"}
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"@utils/check7zip\"\nexport * from \"@utils/execAsync\"\nexport * from \"@utils/install7zip\"\nexport * from \"@utils/saveFile\"\nexport * from \"@utils/spawnAsync\"\nexport * from \"@utils/unzip\"\nexport * from \"@utils/zip\"\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["which","check7zip","error"],"sources":["../../../src/utils/check7zip.ts"],"sourcesContent":["import which from \"which\"\r\n\r\n/**\r\n * 检测 7z 命令是否存在\r\n */\r\nexport async function check7zip() {\r\n try {\r\n await which(\"7z\")\r\n return true\r\n } catch (error) {\r\n return false\r\n }\r\n}\r\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;;AAEzB;AACA;AACA;AACA,OAAO,eAAeC,SAASA,CAAA,EAAG;EAC9B,IAAI;IACA,MAAMD,KAAK,CAAC,IAAI,CAAC;IACjB,OAAO,IAAI;EACf,CAAC,CAAC,OAAOE,KAAK,EAAE;IACZ,OAAO,KAAK;EAChB;AACJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检测到没有安装 7z 时的提示信息
|
|
3
|
+
*/
|
|
4
|
+
export function install7zip() {
|
|
5
|
+
console.log("检测到您的系统没有安装 7z,请先安装 7z 后再执行");
|
|
6
|
+
console.log("下载地址:https://www.7-zip.org/download.html");
|
|
7
|
+
console.log("如果已经安装,请按照以下步骤将 7z 添加到环境变量中");
|
|
8
|
+
console.log("1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量");
|
|
9
|
+
console.log("2. 在系统变量中找到并选中 Path,点击编辑");
|
|
10
|
+
console.log("3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定");
|
|
11
|
+
console.log("4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功");
|
|
12
|
+
console.log("5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确");
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=install7zip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["install7zip","console","log"],"sources":["../../../src/utils/install7zip.ts"],"sourcesContent":["/**\r\n * 检测到没有安装 7z 时的提示信息\r\n */\r\nexport function install7zip() {\r\n console.log(\"检测到您的系统没有安装 7z,请先安装 7z 后再执行\")\r\n console.log(\"下载地址:https://www.7-zip.org/download.html\")\r\n console.log(\"如果已经安装,请按照以下步骤将 7z 添加到环境变量中\")\r\n console.log(\"1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\")\r\n console.log(\"2. 在系统变量中找到并选中 Path,点击编辑\")\r\n console.log(\"3. 点击新建,输入 7z 的安装路径(默认是 C:\\\\Program Files\\\\7-Zip),点击确定\")\r\n console.log(\"4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\")\r\n console.log(\"5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\")\r\n}\r\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CAAA,EAAG;EAC1BC,OAAO,CAACC,GAAG,CAAC,6BAA6B,CAAC;EAC1CD,OAAO,CAACC,GAAG,CAAC,0CAA0C,CAAC;EACvDD,OAAO,CAACC,GAAG,CAAC,6BAA6B,CAAC;EAC1CD,OAAO,CAACC,GAAG,CAAC,qCAAqC,CAAC;EAClDD,OAAO,CAACC,GAAG,CAAC,0BAA0B,CAAC;EACvCD,OAAO,CAACC,GAAG,CAAC,wDAAwD,CAAC;EACrED,OAAO,CAACC,GAAG,CAAC,mCAAmC,CAAC;EAChDD,OAAO,CAACC,GAAG,CAAC,uCAAuC,CAAC;AACxD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createWriteStream } from "fs";
|
|
2
|
+
import { Readable } from "stream";
|
|
3
|
+
/**
|
|
4
|
+
* 保存文件
|
|
5
|
+
*/
|
|
6
|
+
export async function saveFile({
|
|
7
|
+
file,
|
|
8
|
+
target
|
|
9
|
+
}) {
|
|
10
|
+
await new Promise((resolve, reject) => {
|
|
11
|
+
const writeAble = createWriteStream(target);
|
|
12
|
+
Readable.fromWeb(file.stream()).pipe(writeAble).on("finish", resolve).on("error", reject);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=saveFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createWriteStream","Readable","saveFile","file","target","Promise","resolve","reject","writeAble","fromWeb","stream","pipe","on"],"sources":["../../../src/utils/saveFile.ts"],"sourcesContent":["import { createWriteStream } from \"fs\"\r\nimport { Readable } from \"stream\"\r\n\r\nexport type SaveFileOptions = {\r\n /** 要保存的文件 */\r\n file: File\r\n /** 保存文件的目标位置 */\r\n target: string\r\n}\r\n\r\n/**\r\n * 保存文件\r\n */\r\nexport async function saveFile({ file, target }: SaveFileOptions) {\r\n await new Promise((resolve, reject) => {\r\n const writeAble = createWriteStream(target)\r\n Readable.fromWeb(file.stream() as any)\r\n .pipe(writeAble)\r\n .on(\"finish\", resolve)\r\n .on(\"error\", reject)\r\n })\r\n}\r\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,IAAI;AACtC,SAASC,QAAQ,QAAQ,QAAQ;AASjC;AACA;AACA;AACA,OAAO,eAAeC,QAAQA,CAAC;EAAEC,IAAI;EAAEC;AAAwB,CAAC,EAAE;EAC9D,MAAM,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACnC,MAAMC,SAAS,GAAGR,iBAAiB,CAACI,MAAM,CAAC;IAC3CH,QAAQ,CAACQ,OAAO,CAACN,IAAI,CAACO,MAAM,CAAC,CAAQ,CAAC,CACjCC,IAAI,CAACH,SAAS,CAAC,CACfI,EAAE,CAAC,QAAQ,EAAEN,OAAO,CAAC,CACrBM,EAAE,CAAC,OAAO,EAAEL,MAAM,CAAC;EAC5B,CAAC,CAAC;AACN"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type UnzipOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* 要解压的文件
|
|
4
|
+
*/
|
|
5
|
+
source: string;
|
|
6
|
+
/**
|
|
7
|
+
* 解压到的目标位置
|
|
8
|
+
*/
|
|
9
|
+
target: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* 解压文件
|
|
13
|
+
*/
|
|
14
|
+
export declare function unzip({ source, target }: UnzipOptions): Promise<import("./execAsync").ExecResult<string> | undefined>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { check7zip } from "./check7zip";
|
|
2
|
+
import { execAsync } from "./execAsync";
|
|
3
|
+
import { install7zip } from "./install7zip";
|
|
4
|
+
/**
|
|
5
|
+
* 解压文件
|
|
6
|
+
*/
|
|
7
|
+
export async function unzip({
|
|
8
|
+
source,
|
|
9
|
+
target
|
|
10
|
+
}) {
|
|
11
|
+
if (!(await check7zip())) {
|
|
12
|
+
install7zip();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
return await execAsync(`7z x ${source} -o${target}`);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=unzip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["check7zip","execAsync","install7zip","unzip","source","target"],"sources":["../../../src/utils/unzip.ts"],"sourcesContent":["import { check7zip } from \"./check7zip\"\r\nimport { execAsync } from \"./execAsync\"\r\nimport { install7zip } from \"./install7zip\"\r\n\r\nexport type UnzipOptions = {\r\n /**\r\n * 要解压的文件\r\n */\r\n source: string\r\n /**\r\n * 解压到的目标位置\r\n */\r\n target: string\r\n}\r\n\r\n/**\r\n * 解压文件\r\n */\r\nexport async function unzip({ source, target }: UnzipOptions) {\r\n if (!(await check7zip())) {\r\n install7zip()\r\n return\r\n }\r\n return await execAsync(`7z x ${source} -o${target}`)\r\n}\r\n"],"mappings":"AAAA,SAASA,SAAS;AAClB,SAASC,SAAS;AAClB,SAASC,WAAW;AAapB;AACA;AACA;AACA,OAAO,eAAeC,KAAKA,CAAC;EAAEC,MAAM;EAAEC;AAAqB,CAAC,EAAE;EAC1D,IAAI,EAAE,MAAML,SAAS,CAAC,CAAC,CAAC,EAAE;IACtBE,WAAW,CAAC,CAAC;IACb;EACJ;EACA,OAAO,MAAMD,SAAS,CAAE,QAAOG,MAAO,MAAKC,MAAO,EAAC,CAAC;AACxD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ZipOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* 要压缩的文件
|
|
4
|
+
*/
|
|
5
|
+
source: string | string[];
|
|
6
|
+
/**
|
|
7
|
+
* 压缩到的目标位置
|
|
8
|
+
*/
|
|
9
|
+
target: string;
|
|
10
|
+
/**
|
|
11
|
+
* 线程数
|
|
12
|
+
*/
|
|
13
|
+
thread?: number | "auto" | "max";
|
|
14
|
+
/**
|
|
15
|
+
* 压缩等级,0-9
|
|
16
|
+
*/
|
|
17
|
+
level?: number;
|
|
18
|
+
/**
|
|
19
|
+
* 是否加密
|
|
20
|
+
*/
|
|
21
|
+
password?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function zip({ source, target, thread, level, password }: ZipOptions): Promise<import("./execAsync").ExecResult<string> | undefined>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { cpus } from "os";
|
|
2
|
+
import { execAsync } from "./execAsync";
|
|
3
|
+
import { check7zip } from "./check7zip";
|
|
4
|
+
import { install7zip } from "./install7zip";
|
|
5
|
+
export async function zip({
|
|
6
|
+
source,
|
|
7
|
+
target,
|
|
8
|
+
thread = "auto",
|
|
9
|
+
level,
|
|
10
|
+
password
|
|
11
|
+
}) {
|
|
12
|
+
if (!(await check7zip())) {
|
|
13
|
+
install7zip();
|
|
14
|
+
return;
|
|
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}` : ""}`);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=zip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["cpus","execAsync","check7zip","install7zip","zip","source","target","thread","level","password","Array","isArray","join","cpuCount","length"],"sources":["../../../src/utils/zip.ts"],"sourcesContent":["import { cpus } from \"os\"\r\nimport { execAsync } from \"./execAsync\"\r\nimport { check7zip } from \"./check7zip\"\r\nimport { install7zip } from \"./install7zip\"\r\n\r\nexport type ZipOptions = {\r\n /**\r\n * 要压缩的文件\r\n */\r\n source: string | string[]\r\n /**\r\n * 压缩到的目标位置\r\n */\r\n target: 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\nexport async function zip({ source, target, thread = \"auto\", level, password }: ZipOptions) {\r\n if (!(await check7zip())) {\r\n install7zip()\r\n return\r\n }\r\n source = Array.isArray(source) ? source.join(\" \") : source\r\n const cpuCount = cpus().length\r\n if (thread === \"max\") thread = cpuCount\r\n return await execAsync(`7z a ${target} ${source} -mmt=${thread === \"auto\" ? \"on\" : thread}${typeof level === \"number\" ? ` -mx=${level}` : \"\"}${password ? ` -p${password}` : \"\"}`)\r\n}\r\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,IAAI;AACzB,SAASC,SAAS;AAClB,SAASC,SAAS;AAClB,SAASC,WAAW;AAyBpB,OAAO,eAAeC,GAAGA,CAAC;EAAEC,MAAM;EAAEC,MAAM;EAAEC,MAAM,GAAG,MAAM;EAAEC,KAAK;EAAEC;AAAqB,CAAC,EAAE;EACxF,IAAI,EAAE,MAAMP,SAAS,CAAC,CAAC,CAAC,EAAE;IACtBC,WAAW,CAAC,CAAC;IACb;EACJ;EACAE,MAAM,GAAGK,KAAK,CAACC,OAAO,CAACN,MAAM,CAAC,GAAGA,MAAM,CAACO,IAAI,CAAC,GAAG,CAAC,GAAGP,MAAM;EAC1D,MAAMQ,QAAQ,GAAGb,IAAI,CAAC,CAAC,CAACc,MAAM;EAC9B,IAAIP,MAAM,KAAK,KAAK,EAAEA,MAAM,GAAGM,QAAQ;EACvC,OAAO,MAAMZ,SAAS,CAAE,QAAOK,MAAO,IAAGD,MAAO,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;AACtL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soda-nodejs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -24,8 +24,12 @@
|
|
|
24
24
|
"homepage": "https://github.com/1adybug/deepsea/tree/main/packages/soda-nodejs",
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^20.14.10",
|
|
27
|
+
"@types/which": "^3.0.4",
|
|
27
28
|
"father": "^4.5.0-rc.2"
|
|
28
29
|
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"which": "^4.0.0"
|
|
32
|
+
},
|
|
29
33
|
"scripts": {
|
|
30
34
|
"dev": "father dev",
|
|
31
35
|
"build": "father build",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检测到没有安装 7z 时的提示信息
|
|
3
|
+
*/
|
|
4
|
+
export function install7zip() {
|
|
5
|
+
console.log("检测到您的系统没有安装 7z,请先安装 7z 后再执行")
|
|
6
|
+
console.log("下载地址:https://www.7-zip.org/download.html")
|
|
7
|
+
console.log("如果已经安装,请按照以下步骤将 7z 添加到环境变量中")
|
|
8
|
+
console.log("1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量")
|
|
9
|
+
console.log("2. 在系统变量中找到并选中 Path,点击编辑")
|
|
10
|
+
console.log("3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定")
|
|
11
|
+
console.log("4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功")
|
|
12
|
+
console.log("5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确")
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createWriteStream } from "fs"
|
|
2
|
+
import { Readable } from "stream"
|
|
3
|
+
|
|
4
|
+
export type SaveFileOptions = {
|
|
5
|
+
/** 要保存的文件 */
|
|
6
|
+
file: File
|
|
7
|
+
/** 保存文件的目标位置 */
|
|
8
|
+
target: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 保存文件
|
|
13
|
+
*/
|
|
14
|
+
export async function saveFile({ file, target }: SaveFileOptions) {
|
|
15
|
+
await new Promise((resolve, reject) => {
|
|
16
|
+
const writeAble = createWriteStream(target)
|
|
17
|
+
Readable.fromWeb(file.stream() as any)
|
|
18
|
+
.pipe(writeAble)
|
|
19
|
+
.on("finish", resolve)
|
|
20
|
+
.on("error", reject)
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { check7zip } from "./check7zip"
|
|
2
|
+
import { execAsync } from "./execAsync"
|
|
3
|
+
import { install7zip } from "./install7zip"
|
|
4
|
+
|
|
5
|
+
export type UnzipOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* 要解压的文件
|
|
8
|
+
*/
|
|
9
|
+
source: string
|
|
10
|
+
/**
|
|
11
|
+
* 解压到的目标位置
|
|
12
|
+
*/
|
|
13
|
+
target: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 解压文件
|
|
18
|
+
*/
|
|
19
|
+
export async function unzip({ source, target }: UnzipOptions) {
|
|
20
|
+
if (!(await check7zip())) {
|
|
21
|
+
install7zip()
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
return await execAsync(`7z x ${source} -o${target}`)
|
|
25
|
+
}
|
package/src/utils/zip.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { cpus } from "os"
|
|
2
|
+
import { execAsync } from "./execAsync"
|
|
3
|
+
import { check7zip } from "./check7zip"
|
|
4
|
+
import { install7zip } from "./install7zip"
|
|
5
|
+
|
|
6
|
+
export type ZipOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* 要压缩的文件
|
|
9
|
+
*/
|
|
10
|
+
source: string | string[]
|
|
11
|
+
/**
|
|
12
|
+
* 压缩到的目标位置
|
|
13
|
+
*/
|
|
14
|
+
target: string
|
|
15
|
+
/**
|
|
16
|
+
* 线程数
|
|
17
|
+
*/
|
|
18
|
+
thread?: number | "auto" | "max"
|
|
19
|
+
/**
|
|
20
|
+
* 压缩等级,0-9
|
|
21
|
+
*/
|
|
22
|
+
level?: number
|
|
23
|
+
/**
|
|
24
|
+
* 是否加密
|
|
25
|
+
*/
|
|
26
|
+
password?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function zip({ source, target, thread = "auto", level, password }: ZipOptions) {
|
|
30
|
+
if (!(await check7zip())) {
|
|
31
|
+
install7zip()
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
source = Array.isArray(source) ? source.join(" ") : source
|
|
35
|
+
const cpuCount = cpus().length
|
|
36
|
+
if (thread === "max") thread = cpuCount
|
|
37
|
+
return await execAsync(`7z a ${target} ${source} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`)
|
|
38
|
+
}
|