1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 01:52:26 +08:00

forbid bad compression levels

(instead of allowing -1 and treating it as "use default")

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
Steven Allen
2018-01-20 00:55:52 -08:00
parent 888c5fc437
commit 2f964d40e8

View File

@ -46,7 +46,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
cmdkit.StringOption("output", "o", "The path where the output should be stored."),
cmdkit.BoolOption("archive", "a", "Output a TAR archive."),
cmdkit.BoolOption("compress", "C", "Compress the output with GZIP compression."),
cmdkit.IntOption("compression-level", "l", "The level of compression (1-9).").WithDefault(-1),
cmdkit.IntOption("compression-level", "l", "The level of compression (1-9)."),
},
PreRun: func(req *cmds.Request, env cmds.Environment) error {
_, err := getCompressOptions(req)
@ -257,11 +257,11 @@ func (gw *getWriter) writeExtracted(r io.Reader, fpath string) error {
func getCompressOptions(req *cmds.Request) (int, error) {
cmprs, _ := req.Options["compress"].(bool)
cmplvl, _ := req.Options["compression-level"].(int)
cmplvl, cmplvlFound := req.Options["compression-level"].(int)
switch {
case !cmprs:
return gzip.NoCompression, nil
case cmprs && cmplvl == -1:
case cmprs && !cmplvlFound:
return gzip.DefaultCompression, nil
case cmprs && (cmplvl < 1 || cmplvl > 9):
return gzip.NoCompression, ErrInvalidCompressionLevel