()
| 251 | } |
| 252 | |
| 253 | func (config *Config) detectFromFilename() { |
| 254 | var result [][]string |
| 255 | |
| 256 | extensions := map[string]string{ |
| 257 | "tar": "tar", |
| 258 | "zip": "zip", |
| 259 | "gz": "pgzip", |
| 260 | "lz4": "lz4", |
| 261 | "bgzf": "bgzf", |
| 262 | "xz": "xz", |
| 263 | "bzip2": "bzip2", |
| 264 | } |
| 265 | |
| 266 | if config.Format == "" { |
| 267 | result = filenamePattern.FindAllStringSubmatch(config.OutputPath, -1) |
| 268 | } else { |
| 269 | result = filenamePattern.FindAllStringSubmatch(fmt.Sprintf("%s.%s", config.OutputPath, config.Format), -1) |
| 270 | } |
| 271 | |
| 272 | // No dots. Bail out with defaults. |
| 273 | if len(result) == 0 { |
| 274 | config.Algorithm = "pgzip" |
| 275 | config.Archive = "tar" |
| 276 | return |
| 277 | } |
| 278 | |
| 279 | // Parse the last two .groups, if they're there |
| 280 | lastItem := result[len(result)-1][1] |
| 281 | var nextToLastItem string |
| 282 | if len(result) == 1 { |
| 283 | nextToLastItem = "" |
| 284 | } else { |
| 285 | nextToLastItem = result[len(result)-2][1] |
| 286 | } |
| 287 | |
| 288 | // Should we make an archive? E.g. tar or zip? |
| 289 | if nextToLastItem == "tar" { |
| 290 | config.Archive = "tar" |
| 291 | } |
| 292 | if lastItem == "zip" || lastItem == "tar" { |
| 293 | config.Archive = lastItem |
| 294 | // Tar or zip is our final artifact. Bail out. |
| 295 | return |
| 296 | } |
| 297 | |
| 298 | // Should we compress the artifact? |
| 299 | algorithm, ok := extensions[lastItem] |
| 300 | if ok { |
| 301 | config.Algorithm = algorithm |
| 302 | // We found our compression algorithm. Bail out. |
| 303 | return |
| 304 | } |
| 305 | |
| 306 | // We didn't match a known compression format. Default to tar + pgzip |
| 307 | config.Algorithm = "pgzip" |
| 308 | config.Archive = "tar" |
| 309 | } |
| 310 |
no outgoing calls