Internal refactoring to enable opt-out of infer filetype behaviour

This does not change the public API, but gives me a less hacky backdoor to opt-out of infer filetype behaviour than I'm currently using.

@alindeman @myronmarston