It looks like it's using the file extension to determine whether to write a .kml (uncompressed) or .kmz (compressed) xml file.  It calls different functions to write the file depending on the file extension.