An Amusing Bug

I was working this evening on a program for my job which processes some data and writes the results to a file. Thanks to the near-magical boost::iostreams library I can have my program also compress the data as it does so. Today I added some code that's supposed to check the extension of the specified output file name to decide what compression, if any, to use. It seems I made a mistake, although it was not at all immediately obvious. At the moment I've been having the program compress the output using bzip2, so this was the extension of the filename. After the program finished running I navigated to where my file had a appeared and went to open it up to check whether another bug I'm chasing had manifested itself. Just as I expected when I double-clicked the file, Archive Utility poped up and decompressed my file—or so I thought. For the resulting file was not out.xml but out.xml.bz2.zip! Indeed, rather comically, I can then double-click this file, and decompress it back to out.xml.bz2, and from there enter into an endless cycle if I so choose.

After a few seconds thought I realized what was going on, and opening up the supposedly bzipped file with a text editor proved my theory correct: The file was in fact raw text, totally uncompressed. It seems that two effects conspired together: The first is that I apparently screwed up my auto-detection code and so the data is not being compressed at all. The second is that apparently once Archive Utility get hold of a file, it's determined to do something with it, and so it the file isn't in any known compressed format and therefore cannot be decompressed, then it had better be compressed instead.

Fun though that was, I think I'll go fix my code so that it actually compresses when it should.

No Comments

Comment on this post