|
1 | 1 | import { promises as fs } from 'node:fs'; |
2 | | -import { Readable } from 'node:stream'; |
3 | | -import { constants, implode, stream } from 'node-pkware'; |
| 2 | +import { implode } from 'node-pkware/simple'; |
4 | 3 | import type winston from 'winston'; |
5 | 4 | import { type EwbFormat, formatForExtension, knownFormatsList } from './formats'; |
6 | | - |
7 | | -const { COMPRESSION_ASCII, DICTIONARY_SIZE_LARGE } = constants; |
8 | | -const { streamToBuffer, through } = stream; |
| 5 | +import { bufferToArrayBuffer } from './util/buffer'; |
9 | 6 |
|
10 | 7 | // Decompressed bytes per block. Multisim/Ultiboard ship files chunked at this |
11 | 8 | // boundary; matching it keeps the section layout identical to originals. |
12 | 9 | export const DEFAULT_BLOCK_SIZE = 900000; |
13 | 10 |
|
14 | | -function compressBlock(block: Buffer): Promise<Buffer> { |
15 | | - return new Promise<Buffer>((resolve, reject) => { |
16 | | - const src = Readable.from(block); |
17 | | - const compressor = through( |
18 | | - implode(COMPRESSION_ASCII, DICTIONARY_SIZE_LARGE, { |
19 | | - inputBufferSize: block.length, |
20 | | - outputBufferSize: block.length, |
21 | | - }), |
22 | | - ); |
23 | | - src.on('error', reject); |
24 | | - compressor.on('error', reject); |
25 | | - src.pipe(compressor).pipe(streamToBuffer(resolve)); |
26 | | - }); |
| 11 | +function compressBlock(block: Buffer): Buffer { |
| 12 | + return Buffer.from(implode(bufferToArrayBuffer(block), 'ascii', 'large')); |
27 | 13 | } |
28 | 14 |
|
29 | 15 | /** |
@@ -95,7 +81,7 @@ export async function encode(inFile: string, logger: winston.Logger, options: En |
95 | 81 | const end = Math.min(offset + blockSize, totalLength); |
96 | 82 | const slice = xml.subarray(offset, end); |
97 | 83 |
|
98 | | - const compressed = await compressBlock(slice); |
| 84 | + const compressed = compressBlock(slice); |
99 | 85 |
|
100 | 86 | logger.silly(`Section #${section}: ${slice.length} bytes -> ${compressed.length} compressed`); |
101 | 87 |
|
|
0 commit comments