Skip to content

Commit

Permalink
feat(config): remove inputBufferSize and outputBufferSize options to …
Browse files Browse the repository at this point in the history
…reduce code complexity
  • Loading branch information
meszaros-lajos-gyorgy committed Sep 29, 2024
1 parent bfd9a81 commit 1464d24
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 34 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```

Expand All @@ -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)
}
```

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Explode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Implode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/bin/explode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ type AppArgs = {
_: string[]
output?: string
offset?: string
'input-buffer-size'?: string
'output-buffer-size'?: string
version: boolean
'drop-before-offset': boolean
verbose: boolean
v: boolean
}

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',
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions src/bin/implode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 1464d24

Please sign in to comment.