npak-archiver 1.0.1 → 1.0.2
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.js +16 -9
- package/pack.js +5 -14
- package/package.json +1 -1
- package/unpack.js +3 -2
package/index.js
CHANGED
|
@@ -4,10 +4,12 @@ const { execFileSync } = require("child_process");
|
|
|
4
4
|
const { packTargets } = require(path.join(__dirname, "pack.js"));
|
|
5
5
|
const { unpackArchive } = require(path.join(__dirname, "unpack.js"));
|
|
6
6
|
const { handleHumanError } = require(path.join(__dirname, "errors.js"));
|
|
7
|
+
|
|
7
8
|
const rawArgs = process.argv.slice(2);
|
|
8
9
|
const args = [];
|
|
9
10
|
let format = "npak";
|
|
10
11
|
let formatExplicitlySet = false;
|
|
12
|
+
|
|
11
13
|
for (let i = 0; i < rawArgs.length; i++) {
|
|
12
14
|
if ((rawArgs[i] === "--format" || rawArgs[i] === "-f") && rawArgs[i + 1]) {
|
|
13
15
|
format = rawArgs[i + 1].toLowerCase().replace(".", "");
|
|
@@ -17,7 +19,9 @@ for (let i = 0; i < rawArgs.length; i++) {
|
|
|
17
19
|
args.push(rawArgs[i]);
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
|
|
23
|
+
const command = args[0];
|
|
24
|
+
|
|
21
25
|
function delegateToZip(action, sources, target) {
|
|
22
26
|
try {
|
|
23
27
|
const isWin = process.platform === "win32";
|
|
@@ -68,18 +72,18 @@ function delegateToZip(action, sources, target) {
|
|
|
68
72
|
);
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
|
-
if ((command === "pack" || command === "p") && args && args) {
|
|
72
|
-
const source = args;
|
|
73
|
-
const target = args;
|
|
75
|
+
if ((command === "pack" || command === "p") && args[1] && args[2]) {
|
|
76
|
+
const source = args[1];
|
|
77
|
+
const target = args[2];
|
|
74
78
|
|
|
75
79
|
if (format === "zip" || (!formatExplicitlySet && target.endsWith(".zip"))) {
|
|
76
80
|
delegateToZip("pack", source, target);
|
|
77
81
|
} else {
|
|
78
82
|
packTargets(source, target);
|
|
79
83
|
}
|
|
80
|
-
} else if ((command === "unpack" || command === "u") && args && args) {
|
|
81
|
-
const archive = args;
|
|
82
|
-
const targetDir = args;
|
|
84
|
+
} else if ((command === "unpack" || command === "u") && args[1] && args[2]) {
|
|
85
|
+
const archive = args[1];
|
|
86
|
+
const targetDir = args[2];
|
|
83
87
|
|
|
84
88
|
if (format === "zip" || (!formatExplicitlySet && archive.endsWith(".zip"))) {
|
|
85
89
|
delegateToZip("unpack", archive, targetDir);
|
|
@@ -88,7 +92,7 @@ if ((command === "pack" || command === "p") && args && args) {
|
|
|
88
92
|
}
|
|
89
93
|
} else if (command === "pack-auto" && args.length > 1) {
|
|
90
94
|
const targets = args.slice(1).map((p) => path.resolve(p));
|
|
91
|
-
const firstItem = targets;
|
|
95
|
+
const firstItem = targets[0];
|
|
92
96
|
const parentDir = path.dirname(firstItem);
|
|
93
97
|
const baseName =
|
|
94
98
|
targets.length === 1 ? path.parse(firstItem).name : "archive";
|
|
@@ -100,7 +104,10 @@ if ((command === "pack" || command === "p") && args && args) {
|
|
|
100
104
|
const outArchive = path.join(parentDir, `${baseName}.npak`);
|
|
101
105
|
packTargets(targets, outArchive);
|
|
102
106
|
}
|
|
103
|
-
} else if (
|
|
107
|
+
} else if (
|
|
108
|
+
typeof command === "string" &&
|
|
109
|
+
(command.endsWith(".npak") || command.endsWith(".zip"))
|
|
110
|
+
) {
|
|
104
111
|
const archivePath = path.resolve(command);
|
|
105
112
|
const ext = path.extname(archivePath);
|
|
106
113
|
const folderName = path.basename(archivePath, ext);
|
package/pack.js
CHANGED
|
@@ -3,7 +3,7 @@ const path = require("path");
|
|
|
3
3
|
const crypto = require("crypto");
|
|
4
4
|
const rawPalette = require("chalk-palette");
|
|
5
5
|
const chalk_palette = rawPalette.default || rawPalette;
|
|
6
|
-
const { NIBBLE_MAP,
|
|
6
|
+
const { NIBBLE_MAP, charToCode } = require(path.join(__dirname, "codes.js"));
|
|
7
7
|
const { handleHumanError } = require(path.join(__dirname, "errors.js"));
|
|
8
8
|
|
|
9
9
|
class DiskBitWriter {
|
|
@@ -42,20 +42,11 @@ class DiskBitWriter {
|
|
|
42
42
|
|
|
43
43
|
writeString(str) {
|
|
44
44
|
for (const char of str) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
for (let i = 0; i < numStr.length; i++) {
|
|
49
|
-
this.writeNibble(NIBBLE_MAP[numStr[i]]);
|
|
50
|
-
}
|
|
51
|
-
this.writeNibble(NIBBLE_MAP["SEP"]);
|
|
52
|
-
} else {
|
|
53
|
-
const fallback = String(CHAR_TO_NUM["?"]);
|
|
54
|
-
for (let i = 0; i < fallback.length; i++) {
|
|
55
|
-
this.writeNibble(NIBBLE_MAP[fallback[i]]);
|
|
56
|
-
}
|
|
57
|
-
this.writeNibble(NIBBLE_MAP["SEP"]);
|
|
45
|
+
const numStr = String(charToCode(char));
|
|
46
|
+
for (let i = 0; i < numStr.length; i++) {
|
|
47
|
+
this.writeNibble(NIBBLE_MAP[numStr[i]]);
|
|
58
48
|
}
|
|
49
|
+
this.writeNibble(NIBBLE_MAP["SEP"]);
|
|
59
50
|
}
|
|
60
51
|
}
|
|
61
52
|
|
package/package.json
CHANGED
package/unpack.js
CHANGED
|
@@ -3,9 +3,10 @@ const path = require("path");
|
|
|
3
3
|
const crypto = require("crypto");
|
|
4
4
|
const rawPalette = require("chalk-palette");
|
|
5
5
|
const chalk_palette = rawPalette.default || rawPalette;
|
|
6
|
-
const { REV_NIBBLE_MAP,
|
|
6
|
+
const { REV_NIBBLE_MAP, codeToChar } = require(
|
|
7
7
|
path.join(__dirname, "codes.js"),
|
|
8
8
|
);
|
|
9
|
+
|
|
9
10
|
const { handleHumanError } = require(path.join(__dirname, "errors.js"));
|
|
10
11
|
|
|
11
12
|
function unpackArchive(archivePath, targetFolder) {
|
|
@@ -124,7 +125,7 @@ function unpackArchive(archivePath, targetFolder) {
|
|
|
124
125
|
mode = null;
|
|
125
126
|
} else if (token === "SEP") {
|
|
126
127
|
const num = Number(digitBuffer);
|
|
127
|
-
const char =
|
|
128
|
+
const char = codeToChar(num);
|
|
128
129
|
if (mode === "DIR" || mode === "FILE_PATH") {
|
|
129
130
|
currentPath += char;
|
|
130
131
|
} else if (mode === "FILE_DATA") {
|