def loadFile(fName):
    """Loads a NBT file.
    :fName: str/unicode: full file path to load.
    Returns a 5 element tuple: (object nbtObject, string dataKeyName, int savePolicy, int/None magic).
    'magic' is used for PE support."""
    if not fName:
        fName = mcplatform.askOpenFile(title=_("Select a NBT (.dat) file..."), suffixes=['dat', 'nbt'])
    if fName:
        if not os.path.isfile(fName):
            alert("The selected object is not a file.\nCan't load it.")
            return
        savePolicy = 0
        magic = None
        fp = open(fName)
        data = fp.read()
        fp.close()

        _magic = struct.Struct('<i').unpack(data[:4])[0]
            
        if 2 < _magic < 6:
            # We have a PE world.
            magic = _magic
            if struct.Struct('<i').unpack(data[4:8])[0] != len(data[8:]):
                raise NBTFormatError()
            with littleEndianNBT():
                nbtObject = load(buf=data[8:])
            savePolicy = 1
        elif struct.Struct('<i').unpack(data[:4])[0] in (1, 2):
            alert(_("Old PE level.dat, unsupported at the moment."))
        else:
            nbtObject = load(buf=data)
        if fName.endswith('.schematic'):
            t = TAG_Compound(name='Data')
            t.add(nbtObject)
            nbtObject = t
            savePolicy = -1
            dataKeyName = 'Data'
        elif nbtObject.get('Data', None):
            dataKeyName = 'Data'
        elif nbtObject.get('data', None):
            dataKeyName = 'data'
        else:
            nbtObject.name = 'Data'
            dataKeyName = 'Data'
            if savePolicy == 0:
                savePolicy = -1
            nbtObject = TAG_Compound([nbtObject, ])
        return nbtObject, dataKeyName, savePolicy, fName, magic
    return [None] * 5
Loads a NBT file.
    :fName: str/unicode: full file path to load.
    Returns a 5 element tuple: (object nbtObject, string dataKeyName, int savePolicy, int/None magic).
    'magic' is used for PE support.
editortools/nbtexplorer.py