From 1464d242ce09f58e68297d1dcf6a8d0c62e7acec Mon Sep 17 00:00:00 2001 From: Lajos Meszaros Date: Sun, 29 Sep 2024 20:17:08 +0200 Subject: [PATCH] feat(config): remove inputBufferSize and outputBufferSize options to reduce code complexity --- README.md | 10 ++-------- src/Explode.ts | 4 ++-- src/Implode.ts | 4 ++-- src/bin/explode.ts | 6 +----- src/bin/implode.ts | 6 +----- src/types.ts | 12 ------------ 6 files changed, 8 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 2ab68f4..4f87906 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,7 @@ Takes an optional config object, which has the following properties: ```js { - verbose: boolean, // whether the code should display extra debug messages on the console or not (default = false) - inputBufferSize: int, // the starting size of the input buffer, may expand later as needed. Not having to expand may have positive performance impact (default 0) - outputBufferSize: int // same as inputBufferSize, but for the outputBuffer (default 0) + verbose: boolean // whether the code should display extra debug messages on the console or not (default = false) } ``` @@ -83,9 +81,7 @@ Takes an optional config object, which has the following properties: ```js { - verbose: boolean, // whether the code should display extra debug messages on the console or not (default = false) - inputBufferSize: int, // the starting size of the input buffer, may expand later as needed. Not having to expand may have positive performance impact (default 0) - outputBufferSize: int // same as inputBufferSize, but for the outputBuffer (default 0) + verbose: boolean // whether the code should display extra debug messages on the console or not (default = false) } ``` @@ -122,8 +118,6 @@ The returned function has the `(chunk: Buffer, encoding: string, callback: funct `errors.InvalidCompressionTypeError` - thrown by implode when invalid compression type was specified or by explode when it encounters invalid data in the header section (the first 2 bytes of a compressed files) -`errors.InvalidDataError` - thrown by explode, when compressed data is less, than 5 bytes long. Pkware compressed files have 2 bytes header followed by at lest 2 bytes of data and an end literal. - `errors.AbortedError` - thrown by explode when compressed data ends without reaching the end literal or in mid decompression ### examples diff --git a/src/Explode.ts b/src/Explode.ts index 3db05e6..fe6e38a 100644 --- a/src/Explode.ts +++ b/src/Explode.ts @@ -116,8 +116,8 @@ export class Explode { this.backupData = { extraBits: -1, bitBuffer: -1 } this.lengthCodes = generateDecodeTables(LenCode, LenBits) this.distPosCodes = generateDecodeTables(DistCode, DistBits) - this.inputBuffer = new ExpandingBuffer(config?.inputBufferSize ?? 0) - this.outputBuffer = new ExpandingBuffer(config?.outputBufferSize ?? 0) + this.inputBuffer = new ExpandingBuffer(0x1_00_00) + this.outputBuffer = new ExpandingBuffer(0x4_00_00) this.stats = { chunkCounter: 0 } this.compressionType = Compression.Unknown this.dictionarySize = DictionarySize.Unknown diff --git a/src/Implode.ts b/src/Implode.ts index 57915f6..7de38df 100644 --- a/src/Implode.ts +++ b/src/Implode.ts @@ -94,8 +94,8 @@ export class Implode { this.verbose = config?.verbose ?? false this.isFirstChunk = true - this.inputBuffer = new ExpandingBuffer(config?.inputBufferSize ?? 0) - this.outputBuffer = new ExpandingBuffer(config?.outputBufferSize ?? 0) + this.inputBuffer = new ExpandingBuffer(0x1_00_00) + this.outputBuffer = new ExpandingBuffer(0x1_20_00) this.stats = { chunkCounter: 0 } this.compressionType = compressionType this.dictionarySize = dictionarySize diff --git a/src/bin/explode.ts b/src/bin/explode.ts index 8f7dd4c..b0b91f7 100755 --- a/src/bin/explode.ts +++ b/src/bin/explode.ts @@ -18,8 +18,6 @@ type AppArgs = { _: string[] output?: string offset?: string - 'input-buffer-size'?: string - 'output-buffer-size'?: string version: boolean 'drop-before-offset': boolean verbose: boolean @@ -27,7 +25,7 @@ type AppArgs = { } const args: AppArgs = minimist(process.argv.slice(2), { - string: ['output', 'offset', 'input-buffer-size', 'output-buffer-size'], + string: ['output', 'offset'], boolean: ['version', 'drop-before-offset', 'verbose'], alias: { v: 'version', @@ -77,8 +75,6 @@ const offset = parseNumberString(args.offset, 0) const keepHeader = !args['drop-before-offset'] const config: Config = { verbose: args.verbose, - inputBufferSize: parseNumberString(args['input-buffer-size'], 0x1_00_00), - outputBufferSize: parseNumberString(args['output-buffer-size'], 0x4_00_00), } try { diff --git a/src/bin/implode.ts b/src/bin/implode.ts index 0f33bf4..956c54d 100755 --- a/src/bin/implode.ts +++ b/src/bin/implode.ts @@ -19,8 +19,6 @@ type AppArgs = { _: string[] output?: string offset?: string - 'input-buffer-size'?: string - 'output-buffer-size'?: string version: boolean binary: boolean ascii: boolean @@ -38,7 +36,7 @@ type AppArgs = { } const args: AppArgs = minimist(process.argv.slice(2), { - string: ['output', 'offset', 'input-buffer-size', 'output-buffer-size'], + string: ['output', 'offset'], boolean: ['version', 'ascii', 'binary', 'small', 'medium', 'large', 'drop-before-offset', 'verbose'], alias: { v: 'version', @@ -140,8 +138,6 @@ const offset = parseNumberString(args.offset, 0) const keepHeader = !args['drop-before-offset'] const config: Config = { verbose: args.verbose, - inputBufferSize: parseNumberString(args['input-buffer-size'], 0x1_00_00), - outputBufferSize: parseNumberString(args['output-buffer-size'], 0x1_20_00), } try { diff --git a/src/types.ts b/src/types.ts index 26a0660..cb74fa9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,18 +7,6 @@ export type Config = { * @default false */ verbose?: boolean - /** - * The starting size of the input buffer, may expand later as needed. - * Not having to expand may have positive performance impact. - * @default 0 - */ - inputBufferSize?: number - /** - * The starting size of the output buffer, may expand later as needed. - * Not having to expand may have positive performance impact. - * @default 0 - */ - outputBufferSize?: number } export type Stats = {