Use a more reliable format detection method

No point trying to keep track of multiple magic numbers for each format,
just check the extension instead.