Objective-C NSString pathExtension for example.tar.gz?
nsstring, objective-c
Solution
Obviously `pathExtension` is working as expected in this case. The documentation for `pathExtension` says:
The path extension is the portion of the last path component which follows the final period, if there is one.
I can see where you are coming from with your example of a tarred gzipped file. However, I would say that `.gz` is the extension. Unzipping the file (with `gzip`) will result in a `.tar` file which can be extracted with `tar`.
I assume that the convention of naming files with the `.tar.gz` extension started before `tar` was able to also perform the gzip compression. The `gzip` application appends `.gz` to the filename of the file being compressed. For example, gzipping a log file, `access.log`, will result in a file called `access.log.gz`.
The `.tgz` extension has been used for tarred gzipped files particularly where the filename needs to be preserved on file systems that would mangle the extension (e.g. DOS).
Problem
When calling the `pathExtension` method on a string that contains something such as "example.tar.gz" I get ".gz" as the result. I can do some string manipulation to get the real extension, but I'm number wondering if there is a built in method that I'm overlooking? (I have checked the docs, but I don't see anything).