use File.extname to determine extension.

Should fix #520.