Query regarding logic
jeremyquinton opened this issue · 0 comments
jeremyquinton commented
This is a great little library found it really useful. I was just reading the source and Im new to go I had a thought around these lines thought maybe worth mentioning.
https://github.com/jhoonb/archivex/blob/master/archivex.go#L53-L60
if strings.HasSuffix(name, ".zip") != true {
if strings.HasSuffix(name, ".tar.gz") == true {
name = strings.Replace(name, ".tar.gz", ".zip", -1)
} else {
name = name + ".zip"
}
}
z.Name = name
could it not be better written as
if strings.HasSuffix(name, ".zip") == true {
z.Name = name
}
if strings.HasSuffix(name, ".tar.gz") == true {
z.Name = strings.Replace(name, ".tar.gz", ".zip", -1)
}
if z.Name == "" {
z.Name = name + ".zip"
}
the idea being that code with one level of indentation is easier to read. If you think that is an improvement Id be happy to do a PR else you can close my issue. Thanks again for the library works really well.