I wonder if it wouldn't make sense to place all the type discovery into a separate function which would simply gets called fro load?  this way it might come handy for other cases where someone just tries to deduce the type of a file at hands without actualy loading it?