{"record":{"id":"6d37614f4cdff8b0","repo":"ipfs/kubo","slug":"compression-level-must-be-between-1-and-9","errorCode":null,"errorMessage":"compression level must be between 1 and 9","messagePattern":"compression level must be between 1 and 9","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/get.go","lineNumber":25,"sourceCode":"\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\tgopath \"path\"\n\t\"path/filepath\"\n\t\"strings\"\n\n\t\"github.com/ipfs/kubo/core/commands/cmdenv\"\n\t\"github.com/ipfs/kubo/core/commands/cmdutils\"\n\t\"github.com/ipfs/kubo/core/commands/e\"\n\n\t\"github.com/cheggaaa/pb/v3\"\n\t\"github.com/ipfs/boxo/files\"\n\t\"github.com/ipfs/boxo/tar\"\n\tcmds \"github.com/ipfs/go-ipfs-cmds\"\n)\n\nvar ErrInvalidCompressionLevel = errors.New(\"compression level must be between 1 and 9\")\n\nconst (\n\toutputOptionName           = \"output\"\n\tarchiveOptionName          = \"archive\"\n\tcompressOptionName         = \"compress\"\n\tcompressionLevelOptionName = \"compression-level\"\n)\n\nvar GetCmd = &cmds.Command{\n\tHelptext: cmds.HelpText{\n\t\tTagline: \"Download IPFS objects.\",\n\t\tShortDescription: `\nStores to disk the data contained an IPFS or IPNS object(s) at the given path.\n\nBy default, the output will be stored at './<ipfs-path>', but an alternate\npath can be specified with '--output=<path>' or '-o=<path>'.\n\nTo output a TAR archive instead of unpacked files, use '--archive' or '-a'.","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/get.go#L7-L43","documentation":"Kubo's `ipfs get` supports gzip compression of the output. When the `--compress` flag is set, `getCompressOptions` validates the `--compression-level` option and returns the exported sentinel `ErrInvalidCompressionLevel` if the value is not an integer between 1 and 9 (gzip levels). Omitting the level falls back to `gzip.DefaultCompression`, so the error only fires when an out-of-range level is explicitly supplied.","triggerScenarios":"Running `ipfs get <cid> --compress --compression-level=0`, `--compression-level=10`, a negative value, or any non-integer value that parses outside the 1..9 range (e.g. `--compression-level=100`). Only reached when `compress` is true; the level is ignored otherwise.","commonSituations":"Copy-pasted shell scripts with a level variable computed or defaulted to 0; confusing gzip levels (1-9) with other libraries' 0-9 ranges (where 0 means 'store'); passing a zstd-style level that exceeds 9.","solutions":["Set `--compression-level` to an integer between 1 and 9 (1=fastest, 9=best).","Omit `--compression-level` entirely so gzip.DefaultCompression (-1/6) is used.","If you did not intend compression, drop the `--compress` flag and the level is not validated."],"exampleFix":"// before\nipfs get QmXoypB... --compress --compression-level=0\n// after\nipfs get QmXoypB... --compress --compression-level=6","handlingStrategy":"validation","validationCode":"level, err := strconv.Atoi(levelStr)\nif err != nil || level < 1 || level > 9 {\n    return fmt.Errorf(\"compression level must be between 1 and 9, got %q\", levelStr)\n}","typeGuard":"func validGzipLevel(n int) bool { return n >= 1 && n <= 9 }","tryCatchPattern":"lvl, err := getCompressOptions(req)\nif errors.Is(err, cmds.ErrInvalidCompressionLevel) { // sentinel comparison\n    fmt.Fprintln(os.Stderr, \"fix --compression-level: use 1..9 or omit it\")\n    return\n}","preventionTips":["Omit --compression-level unless you need a specific trade-off; the default is gzip.DefaultCompression","Clamp or validate any user/script-supplied level before passing it: level = min(max(level,1),9)","Remember gzip range is 1..9 here; do not carry over 0-9 conventions from zstd or zlib defaults"],"tags":["cli","gzip","validation","options"],"backgroundTag":"invalid-compression-level","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}