node-automator 1.4.18 → 1.4.20

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.
@@ -0,0 +1,25 @@
1
+ const { get_file_list, get_full_path } = require('../utils/file_tool');
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class MergeFileCommand extends BaseCommand {
5
+ async execute() {
6
+ const splitFile = require('split-file');
7
+ let { src, dst } = this.selfData;
8
+ src = get_file_list(src);
9
+ dst = get_full_path(dst);
10
+ const names = await new Promise((resolve, reject) => {
11
+ splitFile.mergeFiles(src, dst)
12
+ .then((names) => {
13
+ resolve(names);
14
+ })
15
+ .catch((err) => {
16
+ reject(err);
17
+ });
18
+ });
19
+ return names;
20
+ }
21
+ }
22
+
23
+ module.exports = {
24
+ MergeFileCommand,
25
+ };
package/commands/mgr.js CHANGED
@@ -120,6 +120,8 @@ const { BackupCommand } = require('./backup');
120
120
  const { CompressCommand } = require('./compress');
121
121
  const { Word2txtCommand } = require('./word2txt');
122
122
  const { ObfuscateCommand } = require('./obfuscate');
123
+ const { SplitFileCommand } = require('./split_file');
124
+ const { MergeFileCommand } = require('./merge_file');
123
125
 
124
126
  const globalData = {
125
127
  "executed_cfg": [], // 执行过的配置文件
@@ -483,6 +485,8 @@ function init() {
483
485
  register("compress", CompressCommand, false);
484
486
  register("word2txt", Word2txtCommand, false);
485
487
  register("obfuscate", ObfuscateCommand, false);
488
+ register("split_file", SplitFileCommand, false);
489
+ register("merge_file", MergeFileCommand, false);
486
490
  }
487
491
 
488
492
  module.exports = {
@@ -0,0 +1,39 @@
1
+ const { get_fst_file, get_full_path } = require('../utils/file_tool');
2
+ const { getByteSize } = require('../utils/transform_tool');
3
+ const { BaseCommand } = require("./base");
4
+
5
+ class SplitFileCommand extends BaseCommand {
6
+ async execute() {
7
+ const splitFile = require('split-file');
8
+ let { src, maxSize, numParts, dst } = this.selfData;
9
+ src = get_fst_file(src);
10
+ dst = get_full_path(dst, "FOLDER");
11
+ maxSize = getByteSize(maxSize);
12
+ const names = await new Promise((resolve, reject) => {
13
+ if (maxSize) {
14
+ splitFile.splitFileBySize(src, maxSize, dst)
15
+ .then((names) => {
16
+ resolve(names);
17
+ })
18
+ .catch((err) => {
19
+ reject(err);
20
+ });
21
+ } else if (numParts) {
22
+ splitFile.splitFile(src, numParts, dst)
23
+ .then((names) => {
24
+ resolve(names);
25
+ })
26
+ .catch((err) => {
27
+ reject(err);
28
+ });
29
+ } else {
30
+ reject("maxSize or numParts is required");
31
+ }
32
+ });
33
+ return names;
34
+ }
35
+ }
36
+
37
+ module.exports = {
38
+ SplitFileCommand,
39
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-automator",
3
- "version": "1.4.18",
3
+ "version": "1.4.20",
4
4
  "description": "Execute automation with yaml configuration(compatible with json)",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -53,6 +53,7 @@
53
53
  "request": "^2.88.2",
54
54
  "request-progress": "^3.0.0",
55
55
  "sharp": "^0.34.3",
56
+ "split-file": "^2.3.0",
56
57
  "spreadsheet-column": "^1.1.1",
57
58
  "strip-json-comments": "^3.1.1",
58
59
  "temp": "^0.9.4",
@@ -1,59 +1,12 @@
1
- function utf8_encode(string) {
2
- string = string.replace(/\r\n/g, "\n");
3
- var utftext = "";
4
- for (var n = 0; n < string.length; n++) {
5
- var c = string.charCodeAt(n);
6
- if (c < 128) {
7
- utftext += String.fromCharCode(c);
8
- } else if ((c > 127) && (c < 2048)) {
9
- utftext += String.fromCharCode((c >> 6) | 192);
10
- utftext += String.fromCharCode((c & 63) | 128);
11
- } else {
12
- utftext += String.fromCharCode((c >> 12) | 224);
13
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
14
- utftext += String.fromCharCode((c & 63) | 128);
15
- }
16
-
17
- }
18
- return utftext;
19
- }
20
-
21
- function utf8_decode(utftext) {
22
- var string = "";
23
- var i = 0;
24
- var c = 0;
25
- var c2 = 0;
26
- var c3 = 0;
27
- while (i < utftext.length) {
28
- c = utftext.charCodeAt(i);
29
- if (c < 128) {
30
- string += String.fromCharCode(c);
31
- i++;
32
- } else if ((c > 191) && (c < 224)) {
33
- c2 = utftext.charCodeAt(i + 1);
34
- string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
35
- i += 2;
36
- } else {
37
- c2 = utftext.charCodeAt(i + 1);
38
- c3 = utftext.charCodeAt(i + 2);
39
- string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
40
- i += 3;
41
- }
42
- }
43
- return string;
44
- }
45
-
46
1
  function encode(string) {
47
- return btoa(utf8_encode(string));
2
+ return Buffer.from(string).toString("base64");
48
3
  }
49
4
 
50
5
  function decode(string) {
51
- return utf8_decode(atob(string));
6
+ return Buffer.from(string, "base64").toString("utf8");
52
7
  }
53
8
 
54
9
  module.exports = {
55
- utf8_encode,
56
- utf8_decode,
57
10
  encode,
58
11
  decode,
59
12
  };