File Extensions Disappear
QUESTION: Yikes! I was excited to see the ability to compress and decompress files built into IDL 8.2.3, but I'm not sure these routines are working correctly. When I compress a file with File_GZip the file extension is removed from the compressed file. Is this a bug?
ANSWER: It certainly looks like a bug to me, but we have learned this seemingly odd behavior is exactly how the gzip program works. Here is an example to help you understand how the program works, and why it looks like a bug.
If you have a file 'picture.png' and you compress it like this:
File_GZip, 'picture.png', 'picture.gz'Then, the file extension is removed in the picture.gz file.
|The PNG file extension is removed.|
When you extract it, the file is extracted without a file extension.But, it is even worse than this, because the file appears to be renamed, too. Consider this code.
file = Filepath(subdir=['examples','data'], 'avhrr.png') File_GZip, file, './test.gz'
Here is what the file looks like if I open the test.gz archive.
|The PNG file extension is removed and the file is renamed!|
This provides a clue for how we might solve the problem. Or, if not a problem, then how to work with this odd program design. Note that if I add an extension to the name of the output file, then the file extension is preserved.
File_GZip, 'picture.png', 'picture.png.gz'
|The PNG file extension is preserved if I add the extension to the output file name.|
Note, too, that if you don't specify the name of the output file, that the default output file name uses the file extension and the file extension is preserved.
|The default output file name preserves the file extension.|
And, finally, note that File_Zipallows you to specify the name of an output file without either changing the names of the file in the archive or losing its file extension.
File_Zip, 'picture.ps', 'testit.zip'
|File_Zip seems to work as you would expect it to work.|
Program Designed this Way
Since this article was first written, we have learned that this odd behavior of File_GZip is totally consistent with the way gzip works. The authors of File_GZip were just being faithful to the published interface and consistent with what users of gzip would expect.
Version of IDL used to prepare this article: IDL 8.2.3.
Updated: 16 June 2013