Skip to content

Commit

Permalink
Defaultd to level 3 if the level is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Jan 22, 2024
1 parent 73ea6b1 commit 1923111
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 52 deletions.
103 changes: 53 additions & 50 deletions v2/app/BlockCompressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type BlockCompressor struct {
entropyCodec string
transform string
blockSize uint
level int // command line compression level
jobs uint
listeners []kanzi.Listener
cpuProf string
Expand All @@ -75,11 +74,58 @@ type fileCompressResult struct {
func NewBlockCompressor(argsMap map[string]any) (*BlockCompressor, error) {
this := &BlockCompressor{}
this.listeners = make([]kanzi.Listener, 0)
this.level = -1
level := -1

if lvl, prst := argsMap["level"]; prst == true {
level = lvl.(int)

if level < 0 || level > 9 {
return nil, fmt.Errorf("Invalid compression level (must be in[0..9]), got %d ", level)
}

if level, prst := argsMap["level"]; prst == true {
this.level = level.(int)
delete(argsMap, "level")
tranformAndCodec := getTransformAndCodec(level)
tokens := strings.Split(tranformAndCodec, "&")
this.transform = tokens[0]
this.entropyCodec = tokens[1]
} else {
codec, prstC := argsMap["entropy"]
transf, prstF := argsMap["transform"]

if prstC == false && prstF == false {
// Default to level 3
tranformAndCodec := getTransformAndCodec(3)
tokens := strings.Split(tranformAndCodec, "&")
this.transform = tokens[0]
this.entropyCodec = tokens[1]
} else {
if prstC == true {
this.entropyCodec = codec.(string)
delete(argsMap, "entropy")
} else {
this.entropyCodec = "NONE"
}

if prstF == true {
strTransf := transf.(string)
delete(argsMap, "transform")

// Extract transform names. Curate input (EG. NONE+NONE+xxxx => xxxx)
name, err := transform.GetType(strTransf)

if err != nil {
return nil, err
}

if strTransf, err = transform.GetName(name); err != nil {
return nil, err
}

this.transform = strTransf
} else {
this.transform = "NONE"
}
}
}

if force, prst := argsMap["overwrite"]; prst == true {
Expand Down Expand Up @@ -117,25 +163,6 @@ func NewBlockCompressor(argsMap map[string]any) (*BlockCompressor, error) {
this.outputName = _COMP_STDOUT
}

strTransf := ""
strCodec := ""

if this.level >= 0 {
tranformAndCodec := getTransformAndCodec(this.level)
tokens := strings.Split(tranformAndCodec, "&")
strTransf = tokens[0]
strCodec = tokens[1]
} else {
if codec, prst := argsMap["entropy"]; prst == true {
strCodec = codec.(string)
delete(argsMap, "entropy")
} else {
strCodec = "ANS0"
}
}

this.entropyCodec = strCodec

if block, prst := argsMap["blockSize"]; prst == true {
szBlk := block.(uint)
this.blockSize = ((szBlk + 15) >> 4) << 4
Expand All @@ -149,7 +176,7 @@ func NewBlockCompressor(argsMap map[string]any) (*BlockCompressor, error) {
return nil, fmt.Errorf("Maximum block size is %d GB (%d bytes), got %d bytes", _COMP_MAX_BLOCK_SIZE/(1024*1024*1024), _COMP_MAX_BLOCK_SIZE, this.blockSize)
}
} else {
switch this.level {
switch level {
case 6:
this.blockSize = 2 * _COMP_DEFAULT_BLOCK_SIZE
case 7:
Expand All @@ -163,28 +190,6 @@ func NewBlockCompressor(argsMap map[string]any) (*BlockCompressor, error) {
}
}

if len(strTransf) == 0 {
if transf, prst := argsMap["transform"]; prst == true {
strTransf = transf.(string)
delete(argsMap, "transform")
} else {
strTransf = "BWT+RANK+ZRLT"
}

// Extract transform names. Curate input (EG. NONE+NONE+xxxx => xxxx)
name, err := transform.GetType(strTransf)

if err != nil {
return nil, err
}

if strTransf, err = transform.GetName(name); err != nil {
return nil, err
}
}

this.transform = strTransf

if check, prst := argsMap["checksum"]; prst == true {
this.checksum = check.(bool)
delete(argsMap, "checksum")
Expand Down Expand Up @@ -231,10 +236,8 @@ func NewBlockCompressor(argsMap map[string]any) (*BlockCompressor, error) {
concurrency = 1
}
} else if concurrency > _COMP_MAX_CONCURRENCY {
if this.verbosity > 0 {
fmt.Printf("Warning: the number of jobs is too high, defaulting to %d\n", _COMP_MAX_CONCURRENCY)
}

msg := fmt.Sprintf("Warning: the number of jobs is too high, defaulting to %d\n", _COMP_MAX_CONCURRENCY)
log.Println(msg, this.verbosity > 0)
concurrency = _COMP_MAX_CONCURRENCY
}

Expand Down
4 changes: 2 additions & 2 deletions v2/app/Kanzi.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ func printHelp(mode string, showHeader bool) {
log.Println(" -l, --level=<compression>", true)
log.Println(" set the compression level [0..9]", true)
log.Println(" Providing this option forces entropy and transform.", true)
log.Println(" Defaults to level 3 if not provided.", true)
log.Println(" 0=None&None (store)", true)
log.Println(" 1=PACK+LZ&NONE", true)
log.Println(" 2=PACK+LZ&HUFFMAN", true)
Expand All @@ -894,11 +895,10 @@ func printHelp(mode string, showHeader bool) {
log.Println(" 9=EXE+RLT+TEXT+UTF&TPAQX\n", true)
log.Println(" -e, --entropy=<codec>", true)
log.Println(" entropy codec [None|Huffman|ANS0|ANS1|Range|FPAQ|TPAQ|TPAQX|CM]", true)
log.Println(" (default is ANS0)\n", true)
log.Println(" -t, --transform=<codec>", true)
log.Println(" transform [None|BWT|BWTS|LZ|LZX|LZP|ROLZ|ROLZX|RLT|ZRLT]", true)
log.Println(" [MTFT|RANK|SRT|TEXT|MM|EXE|UTF|PACK]", true)
log.Println(" EG: BWT+RANK or BWTS+MTFT (default is BWT+RANK+ZRLT)\n", true)
log.Println(" EG: BWT+RANK or BWTS+MTFT", true)
log.Println(" -x, --checksum", true)
log.Println(" enable block checksum\n", true)
log.Println(" -s, --skip", true)
Expand Down

0 comments on commit 1923111

Please sign in to comment.