Refactor the metadata obtaining code so that the entire file doesn't have to be
interpreted in order to read the metadata.