node-pkware 1.0.2 → 2.0.0
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 +12 -12
- package/bin/explode.js +2 -2
- package/bin/implode.js +2 -2
- package/package.json +21 -12
- package/src/explode.js +8 -8
- package/src/implode.js +6 -6
- package/types/explode.d.ts +1 -1
- package/types/helpers/Shared.d.ts +2 -2
- package/types/implode.d.ts +4 -4
package/README.md
CHANGED
|
@@ -34,13 +34,13 @@ Calling either explode or implode with the `-v` or `--version` flag will display
|
|
|
34
34
|
|
|
35
35
|
`implode test/files/fast.fts.unpacked --output=C:/fast.fts --binary --large --offset=1816`
|
|
36
36
|
|
|
37
|
-
`explode test/files/fast.fts --auto-detect --
|
|
37
|
+
`explode test/files/fast.fts --auto-detect --verbose --output=E:/fast.fts.unpacked`
|
|
38
38
|
|
|
39
|
-
`explode test/files/fast.fts --auto-detect --
|
|
39
|
+
`explode test/files/fast.fts --auto-detect --verbose --output=E:/fast.fts.unpacked --offset=2000`
|
|
40
40
|
|
|
41
41
|
### piping also works
|
|
42
42
|
|
|
43
|
-
**Don't use --
|
|
43
|
+
**Don't use --verbose when piping, because verbose messages will be outputted to where the decompressed data is being outputted!**
|
|
44
44
|
|
|
45
45
|
`cat c:/arx/level8.llf | explode > c:/arx/level8.llf.unpacked`
|
|
46
46
|
|
|
@@ -66,7 +66,7 @@ Takes an optional config object, which has the following properties:
|
|
|
66
66
|
|
|
67
67
|
```js
|
|
68
68
|
{
|
|
69
|
-
|
|
69
|
+
verbose: boolean, // whether the code should display extra debug messages on the console or not (default = false)
|
|
70
70
|
inputBufferSize: int, // the starting size of the input buffer, may expand later as needed. Not having to expand may have performance impact (default 0)
|
|
71
71
|
outputBufferSize: int // same as inputBufferSize, but for the outputBuffer (default 0)
|
|
72
72
|
}
|
|
@@ -80,7 +80,7 @@ Takes an optional config object, which has the following properties:
|
|
|
80
80
|
|
|
81
81
|
```js
|
|
82
82
|
{
|
|
83
|
-
|
|
83
|
+
verbose: boolean, // whether the code should display extra debug messages on the console or not (default = false)
|
|
84
84
|
inputBufferSize: int, // the starting size of the input buffer, may expand later as needed. Not having to expand may have performance impact (default 0)
|
|
85
85
|
outputBufferSize: int // same as inputBufferSize, but for the outputBuffer (default 0)
|
|
86
86
|
}
|
|
@@ -148,9 +148,9 @@ const { through, streamToBuffer } = stream
|
|
|
148
148
|
Readable.from(buffer) // buffer is of type Buffer with compressed data
|
|
149
149
|
.pipe(through(explode()))
|
|
150
150
|
.pipe(
|
|
151
|
-
streamToBuffer(decompressedData => {
|
|
151
|
+
streamToBuffer((decompressedData) => {
|
|
152
152
|
// decompressedData holds the decompressed buffer
|
|
153
|
-
})
|
|
153
|
+
}),
|
|
154
154
|
)
|
|
155
155
|
```
|
|
156
156
|
|
|
@@ -190,18 +190,18 @@ const { explode, stream } = require('node-pkware')
|
|
|
190
190
|
const { through } = stream
|
|
191
191
|
|
|
192
192
|
fs.createReadStream(`path-to-compressed-file`)
|
|
193
|
-
.on('error', err => {
|
|
193
|
+
.on('error', (err) => {
|
|
194
194
|
console.error('readstream error')
|
|
195
195
|
})
|
|
196
196
|
.pipe(
|
|
197
|
-
through(explode()).on('error', err => {
|
|
197
|
+
through(explode()).on('error', (err) => {
|
|
198
198
|
console.error('explode error')
|
|
199
|
-
})
|
|
199
|
+
}),
|
|
200
200
|
)
|
|
201
201
|
.pipe(
|
|
202
|
-
fs.createWriteStream(`path-to-write-decompressed-data`).on('error', err => {
|
|
202
|
+
fs.createWriteStream(`path-to-write-decompressed-data`).on('error', (err) => {
|
|
203
203
|
console.error('writestream error')
|
|
204
|
-
})
|
|
204
|
+
}),
|
|
205
205
|
)
|
|
206
206
|
```
|
|
207
207
|
|
package/bin/explode.js
CHANGED
|
@@ -8,7 +8,7 @@ const { explode } = require('../src/explode.js')
|
|
|
8
8
|
|
|
9
9
|
const args = minimist(process.argv.slice(2), {
|
|
10
10
|
string: ['output', 'offset', 'input-buffer-size', 'output-buffer-size'],
|
|
11
|
-
boolean: ['version', 'drop-before-offset', '
|
|
11
|
+
boolean: ['version', 'drop-before-offset', 'verbose'],
|
|
12
12
|
alias: {
|
|
13
13
|
v: 'version',
|
|
14
14
|
},
|
|
@@ -62,7 +62,7 @@ const decompress = (input, output, offset, keepHeader, config) => {
|
|
|
62
62
|
|
|
63
63
|
const keepHeader = !args['drop-before-offset']
|
|
64
64
|
const config = {
|
|
65
|
-
|
|
65
|
+
verbose: args.verbose,
|
|
66
66
|
inputBufferSize: parseNumberString(args['input-buffer-size'], 0x10000),
|
|
67
67
|
outputBufferSize: parseNumberString(args['output-buffer-size'], 0x40000),
|
|
68
68
|
}
|
package/bin/implode.js
CHANGED
|
@@ -26,7 +26,7 @@ const decompress = (input, output, offset, keepHeader, compressionType, dictiona
|
|
|
26
26
|
|
|
27
27
|
const args = minimist(process.argv.slice(2), {
|
|
28
28
|
string: ['output', 'offset', 'input-buffer-size', 'output-buffer-size'],
|
|
29
|
-
boolean: ['version', 'binary', 'ascii', 'drop-before-offset', '
|
|
29
|
+
boolean: ['version', 'binary', 'ascii', 'drop-before-offset', 'verbose', 'small', 'medium', 'large'],
|
|
30
30
|
alias: {
|
|
31
31
|
a: 'ascii',
|
|
32
32
|
b: 'binary',
|
|
@@ -100,7 +100,7 @@ const args = minimist(process.argv.slice(2), {
|
|
|
100
100
|
|
|
101
101
|
const keepHeader = !args['drop-before-offset']
|
|
102
102
|
const config = {
|
|
103
|
-
|
|
103
|
+
verbose: args.verbose,
|
|
104
104
|
inputBufferSize: parseNumberString(args['input-buffer-size'], 0x10000),
|
|
105
105
|
outputBufferSize: parseNumberString(args['output-buffer-size'], 0x12000),
|
|
106
106
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-pkware",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "The nodejs implementation of StormLib's pkware compressor/de-compressor",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -36,27 +36,27 @@
|
|
|
36
36
|
"ramda": "^0.28.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^18.
|
|
40
|
-
"arx-header-size": "^0.
|
|
39
|
+
"@types/node": "^18.11.10",
|
|
40
|
+
"arx-header-size": "^2.0.0",
|
|
41
41
|
"binary-comparator": "^0.5.0",
|
|
42
|
-
"esbuild": "^0.15.
|
|
43
|
-
"eslint": "^8.
|
|
42
|
+
"esbuild": "^0.15.16",
|
|
43
|
+
"eslint": "^8.28.0",
|
|
44
44
|
"eslint-config-prettier": "^8.5.0",
|
|
45
45
|
"eslint-config-prettier-standard": "^4.0.1",
|
|
46
46
|
"eslint-config-standard": "^17.0.0",
|
|
47
47
|
"eslint-plugin-import": "^2.26.0",
|
|
48
48
|
"eslint-plugin-node": "^11.1.0",
|
|
49
49
|
"eslint-plugin-prettier": "^4.2.1",
|
|
50
|
-
"eslint-plugin-promise": "^6.
|
|
50
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
51
51
|
"eslint-plugin-ramda": "^2.5.1",
|
|
52
52
|
"eslint-plugin-standard": "^4.1.0",
|
|
53
|
-
"lint-staged": "^13.0.
|
|
54
|
-
"mocha": "^10.
|
|
55
|
-
"nodemon": "^2.0.
|
|
53
|
+
"lint-staged": "^13.0.4",
|
|
54
|
+
"mocha": "^10.1.0",
|
|
55
|
+
"nodemon": "^2.0.20",
|
|
56
56
|
"pre-commit": "^1.2.2",
|
|
57
|
-
"prettier": "^2.
|
|
57
|
+
"prettier": "^2.8.0",
|
|
58
58
|
"prettier-config-standard": "^5.0.0",
|
|
59
|
-
"typescript": "^4.
|
|
59
|
+
"typescript": "^4.9.3"
|
|
60
60
|
},
|
|
61
61
|
"pre-commit": [
|
|
62
62
|
"lint:staged",
|
|
@@ -65,5 +65,14 @@
|
|
|
65
65
|
],
|
|
66
66
|
"lint-staged": {
|
|
67
67
|
"*.js": "eslint --fix"
|
|
68
|
-
}
|
|
68
|
+
},
|
|
69
|
+
"keywords": [
|
|
70
|
+
"arx-fatalis",
|
|
71
|
+
"pkware",
|
|
72
|
+
"stormlib",
|
|
73
|
+
"implode",
|
|
74
|
+
"explode",
|
|
75
|
+
"compression",
|
|
76
|
+
"blast"
|
|
77
|
+
]
|
|
69
78
|
}
|
package/src/explode.js
CHANGED
|
@@ -104,7 +104,7 @@ const generateAsciiTables = () => {
|
|
|
104
104
|
return tables
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
const parseInitialData = (state,
|
|
107
|
+
const parseInitialData = (state, verbose = false) => {
|
|
108
108
|
if (state.inputBuffer.size() < 4) {
|
|
109
109
|
return false
|
|
110
110
|
}
|
|
@@ -124,7 +124,7 @@ const parseInitialData = (state, debug = false) => {
|
|
|
124
124
|
})
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
if (
|
|
127
|
+
if (verbose) {
|
|
128
128
|
console.log(`explode: compression type: ${state.compressionType === COMPRESSION_BINARY ? 'binary' : 'ascii'}`)
|
|
129
129
|
console.log(
|
|
130
130
|
`explode: compression level: ${
|
|
@@ -244,13 +244,13 @@ const decodeDistance = (state, repeatLength) => {
|
|
|
244
244
|
return distance + 1
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
const processChunkData = (state,
|
|
247
|
+
const processChunkData = (state, verbose = false) => {
|
|
248
248
|
if (state.inputBuffer.isEmpty()) {
|
|
249
249
|
return
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
if (!has('compressionType', state)) {
|
|
253
|
-
const parsedHeader = parseInitialData(state,
|
|
253
|
+
const parsedHeader = parseInitialData(state, verbose)
|
|
254
254
|
if (!parsedHeader || state.inputBuffer.isEmpty()) {
|
|
255
255
|
return
|
|
256
256
|
}
|
|
@@ -309,7 +309,7 @@ const generateDecodeTables = (startIndexes, lengthBits) => {
|
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
const explode = (config = {}) => {
|
|
312
|
-
const {
|
|
312
|
+
const { verbose = false, inputBufferSize = 0x0, outputBufferSize = 0x0 } = config
|
|
313
313
|
|
|
314
314
|
const handler = function (chunk, encoding, callback) {
|
|
315
315
|
if (!isFunction(callback)) {
|
|
@@ -327,11 +327,11 @@ const explode = (config = {}) => {
|
|
|
327
327
|
this._flush = state.onInputFinished
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
if (
|
|
330
|
+
if (verbose) {
|
|
331
331
|
console.log(`explode: reading ${toHex(chunk.length)} bytes from chunk #${state.stats.chunkCounter++}`)
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
processChunkData(state,
|
|
334
|
+
processChunkData(state, verbose)
|
|
335
335
|
|
|
336
336
|
const blockSize = 0x1000
|
|
337
337
|
if (state.outputBuffer.size() > blockSize) {
|
|
@@ -364,7 +364,7 @@ const explode = (config = {}) => {
|
|
|
364
364
|
onInputFinished: (callback) => {
|
|
365
365
|
const state = handler._state
|
|
366
366
|
|
|
367
|
-
if (
|
|
367
|
+
if (verbose) {
|
|
368
368
|
console.log('---------------')
|
|
369
369
|
console.log('explode: total number of chunks read:', state.stats.chunkCounter)
|
|
370
370
|
console.log('explode: inputBuffer heap size', toHex(state.inputBuffer.heapSize()))
|
package/src/implode.js
CHANGED
|
@@ -178,7 +178,7 @@ const handleFirstTwoBytes = (state) => {
|
|
|
178
178
|
state.startIndex += 2
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
const processChunkData = (state,
|
|
181
|
+
const processChunkData = (state, verbose = false) => {
|
|
182
182
|
if (!has('dictionarySizeMask', state)) {
|
|
183
183
|
setup(state)
|
|
184
184
|
}
|
|
@@ -271,7 +271,7 @@ const processChunkData = (state, debug = false) => {
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
const implode = (compressionType, dictionarySizeBits, config = {}) => {
|
|
274
|
-
const {
|
|
274
|
+
const { verbose = false, inputBufferSize = 0x0, outputBufferSize = 0x0 } = config
|
|
275
275
|
|
|
276
276
|
const handler = function (chunk, encoding, callback) {
|
|
277
277
|
if (!isFunction(callback)) {
|
|
@@ -288,11 +288,11 @@ const implode = (compressionType, dictionarySizeBits, config = {}) => {
|
|
|
288
288
|
this._flush = state.onInputFinished
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
if (
|
|
291
|
+
if (verbose) {
|
|
292
292
|
console.log(`implode: reading ${toHex(chunk.length)} bytes from chunk #${state.stats.chunkCounter++}`)
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
processChunkData(state,
|
|
295
|
+
processChunkData(state, verbose)
|
|
296
296
|
|
|
297
297
|
const blockSize = 0x800
|
|
298
298
|
if (state.outputBuffer.size() > blockSize) {
|
|
@@ -330,9 +330,9 @@ const implode = (compressionType, dictionarySizeBits, config = {}) => {
|
|
|
330
330
|
const state = handler._state
|
|
331
331
|
state.streamEnded = true
|
|
332
332
|
try {
|
|
333
|
-
processChunkData(state,
|
|
333
|
+
processChunkData(state, verbose)
|
|
334
334
|
|
|
335
|
-
if (
|
|
335
|
+
if (verbose) {
|
|
336
336
|
console.log('---------------')
|
|
337
337
|
console.log('implode: total number of chunks read:', state.stats.chunkCounter)
|
|
338
338
|
console.log('implode: inputBuffer heap size', toHex(state.inputBuffer.heapSize()))
|
package/types/explode.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export function generateAsciiTables(): {
|
|
|
49
49
|
asciiTable2E34: number[]
|
|
50
50
|
asciiTable2EB4: number[]
|
|
51
51
|
}
|
|
52
|
-
export function processChunkData(state: PrivateExplodeState,
|
|
52
|
+
export function processChunkData(state: PrivateExplodeState, verbose?: boolean): void
|
|
53
53
|
export function wasteBits(state: PrivateExplodeState, numberOfBits: number): typeof PKDCL_STREAM_END | typeof PKDCL_OK
|
|
54
54
|
export function decodeNextLiteral(state: PrivateExplodeState): typeof LITERAL_STREAM_ABORTED | number
|
|
55
55
|
export function decodeDistance(state: PrivateExplodeState, repeatLength: number): number
|
|
@@ -27,10 +27,10 @@ export type PrivateState<T> = { _state: T }
|
|
|
27
27
|
*/
|
|
28
28
|
export type Config = {
|
|
29
29
|
/**
|
|
30
|
-
* Whether the code should display
|
|
30
|
+
* Whether the code should display extra messages on the console or not
|
|
31
31
|
* @default false
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
verbose?: boolean
|
|
34
34
|
/**
|
|
35
35
|
* The starting size of the input buffer, may expand later as needed.
|
|
36
36
|
* Not having to expand may have performance impact.
|
package/types/implode.d.ts
CHANGED
|
@@ -39,15 +39,15 @@ export function getSizeOfMatching(inputBytes: number[], a: number, b: number): n
|
|
|
39
39
|
export function findRepetitions(
|
|
40
40
|
inputBytes: number[],
|
|
41
41
|
endOfLastMatch: number,
|
|
42
|
-
cursor: number
|
|
42
|
+
cursor: number,
|
|
43
43
|
): { size: number; distance: number }
|
|
44
44
|
export function isRepetitionFlushable(
|
|
45
45
|
size: number,
|
|
46
46
|
distance: number,
|
|
47
47
|
startIndex: number,
|
|
48
|
-
inputBufferSize: number
|
|
48
|
+
inputBufferSize: number,
|
|
49
49
|
): boolean | null
|
|
50
|
-
export function processChunkData(state: PrivateExplodeState,
|
|
50
|
+
export function processChunkData(state: PrivateExplodeState, verbose?: boolean): void
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Compresses stream
|
|
@@ -59,5 +59,5 @@ export function processChunkData(state: PrivateExplodeState, debug?: boolean): v
|
|
|
59
59
|
export function implode(
|
|
60
60
|
compressionType: CompressionType,
|
|
61
61
|
dictionarySizeBits: DictionarySizeBits,
|
|
62
|
-
config?: Config
|
|
62
|
+
config?: Config,
|
|
63
63
|
): PrivateState<PrivateExplodeState> & Handler
|