Robuster parsing and allow reading from a file-object

Works in quick tests. May be marginally slower than the previous implementation, but the metadata shouldn't be too heavy for this.