def unpack(file_array, args):
    'Unpacks one or more files given the provided arguments.\n    \n    If contents exist in the target output folder, they will be overwritten.'
    if (not args.quiet):
        print('Unpacking {} files...'.format(len(file_array)))
    is_multiple = (len(file_array) != 1)
    for file_path in file_array:
        try:
            if (not os.path.isfile(file_path)):
                print(('Error: File not found: ' + file_path), file=sys.stderr)
                continue
            basename = os.path.basename(os.path.realpath(file_path))
            if ((len(basename) <= 4) or (basename[(- 4):].upper() != '.DAT')):
                if (not is_multiple):
                    print(('Error: Not an archive of the correct format [file name error]: ' + file_path), file=sys.stderr)
                continue
            dirname = (basename[:(- 4)] + '/')
            if ((not args.quiet) or args.test):
                print(basename)
            with open(file_path, 'rb') as f:
                pos = 0
                (magic, pos) = read_uint32(f, pos)
                if (magic != 12345678):
                    if (not is_multiple):
                        print(('Error: Not an archive of the correct format [magic number error]: ' + file_path), file=sys.stderr)
                    continue
                (ft_count, pos) = read_uint32(f, pos)
                file_tables = []
                for x in range(0, ft_count):
                    (ftext, pos) = read_strn(f, pos, 4)
                    (ftpos, pos) = read_uint32(f, pos)
                    (ftnum, pos) = read_uint32(f, pos)
                    ft = {'name': ftext, 'count': ftnum, 'pos': ftpos, 'files': []}
                    for y in range(0, ftnum):
                        (fdnam, ftpos) = read_strn(f, ftpos, 8)
                        (fdsiz, ftpos) = read_uint32(f, ftpos)
                        (fdpos, ftpos) = read_uint32(f, ftpos)
                        fd = {'name': fdnam, 'size': fdsiz, 'pos': fdpos}
                        ft['files'].append(fd)
                    file_tables.append(ft)
                if args.test:
                    pp = pprint.PrettyPrinter(indent=4)
                    pp.pprint(file_tables)
                else:
                    if (not os.path.isdir(dirname)):
                        os.mkdir(dirname)
                    for ft in file_tables:
                        for fd in ft['files']:
                            out_path = os.path.join(dirname, ((fd['name'] + '.') + ft['name']))
                            if (not args.quiet):
                                print(out_path)
                            with open(out_path, 'wb') as fo:
                                f.seek(fd['pos'])
                                fo.write(f.read(fd['size']))
        except Exception as err:
            print(('Error: Uncaught exception parsing file: ' + file_path), file=sys.stderr)
            print('{}'.format(err), file=sys.stderr)
            if (not args.quiet):
                traceback.print_exc()
            continue
Unpacks one or more files given the provided arguments.

If contents exist in the target output folder, they will be overwritten.
def unpack(file_array, args):
    'Unpacks one or more files given the provided arguments.\n    \n    If contents exist in the target output folder, they will be overwritten.'
    if (not args.quiet):
        print('Unpacking {} files...'.format(len(file_array)))
    is_multiple = (len(file_array) != 1)
    for file_path in file_array:
        try:
            if (not os.path.isfile(file_path)):
                print(('Error: File not found: ' + file_path), file=sys.stderr)
                continue
            basename = os.path.basename(os.path.realpath(file_path))
            if ((len(basename) <= 4) or (basename[(- 4):].upper() != '.DAT')):
                if (not is_multiple):
                    print(('Error: Not an archive of the correct format [file name error]: ' + file_path), file=sys.stderr)
                continue
            dirname = (basename[:(- 4)] + '/')
            if ((not args.quiet) or args.test):
                print(basename)
            with open(file_path, 'rb') as f:
                pos = 0
                (magic, pos) = read_uint32(f, pos)
                if (magic != 12345678):
                    if (not is_multiple):
                        print(('Error: Not an archive of the correct format [magic number error]: ' + file_path), file=sys.stderr)
                    continue
                (ft_count, pos) = read_uint32(f, pos)
                file_tables = []
                for x in range(0, ft_count):
                    (ftext, pos) = read_strn(f, pos, 4)
                    (ftpos, pos) = read_uint32(f, pos)
                    (ftnum, pos) = read_uint32(f, pos)
                    ft = {'name': ftext, 'count': ftnum, 'pos': ftpos, 'files': []}
                    for y in range(0, ftnum):
                        (fdnam, ftpos) = read_strn(f, ftpos, 8)
                        (fdsiz, ftpos) = read_uint32(f, ftpos)
                        (fdpos, ftpos) = read_uint32(f, ftpos)
                        fd = {'name': fdnam, 'size': fdsiz, 'pos': fdpos}
                        ft['files'].append(fd)
                    file_tables.append(ft)
                if args.test:
                    pp = pprint.PrettyPrinter(indent=4)
                    pp.pprint(file_tables)
                else:
                    if (not os.path.isdir(dirname)):
                        os.mkdir(dirname)
                    for ft in file_tables:
                        for fd in ft['files']:
                            out_path = os.path.join(dirname, ((fd['name'] + '.') + ft['name']))
                            if (not args.quiet):
                                print(out_path)
                            with open(out_path, 'wb') as fo:
                                f.seek(fd['pos'])
                                fo.write(f.read(fd['size']))
        except Exception as err:
            print(('Error: Uncaught exception parsing file: ' + file_path), file=sys.stderr)
            print('{}'.format(err), file=sys.stderr)
            if (not args.quiet):
                traceback.print_exc()
            continue