On-the-fly file type switching.

@jankeromnes, want to take a stab at a review?