Magic numbers embedded in the file are an ugly workaround. One old idea is to put the file type indicator is in the file descriptor - like the executable bit in *nix.
I recall that Digital RMS did something of the kind. But I also recall that VMS disks tended to contain lots of files that were simply untyped streams.