<commit_before>__author__ = 'mongolrgata'

import os
import sys
import struct


def read_unsigned_int32(file):
    """
    :param file:
    :type file: io.FileIO
    :return:
    :rtype: int
    """

    return struct.unpack('<L', file.read(4))[0]


def read_char16(file):
    """
    :param file:
    :type file: io.FileIO
    :return:
    :rtype: str
    """

    return chr(struct.unpack('<H', file.read(2))[0])


def read_filename(file):
    """
    :param file:
    :type file: io.FileIO
    :return:
    :rtype: str
    """

    result = ''

    while True:
        char = read_char16(file)

        if char == '\x00':
            break

        result += char

    return result


def extract(arc_filename):
    """
    :param arc_filename:
    :type arc_filename: str
    :return:
    """

    with open(arc_filename, 'rb') as arc_file:
        file_count = read_unsigned_int32(arc_file)
        read_unsigned_int32(arc_file)  # header_length

        file_lengths = []
        file_names = []

        directory = os.path.splitext(arc_filename)[0]
        if not os.path.exists(directory):
            os.mkdir(directory)

        for i in range(0, file_count):
            file_lengths.append(read_unsigned_int32(arc_file))
            read_unsigned_int32(arc_file)  # file_offset
            file_names.append(os.path.join(directory, read_filename(arc_file)))

        for i in range(0, file_count):
            with open(file_names[i], 'wb+') as file_out:
                file_out.write(arc_file.read(file_lengths[i]))


def main():
    extract(sys.argv[1])


if __name__ == '__main__':
    main()<commit_msg>Через seek<commit_after>__author__ = 'mongolrgata'

import os
import sys
import struct


def read_unsigned_int32(file):
    """
    :param file:
    :type file: io.FileIO
    :return:
    :rtype: int
    """

    return struct.unpack('<L', file.read(4))[0]


def read_char16(file):
    """
    :param file:
    :type file: io.FileIO
    :return:
    :rtype: str
    """

    return chr(struct.unpack('<H', file.read(2))[0])


def read_filename(file):
    """
    :param file:
    :type file: io.FileIO
    :return:
    :rtype: str
    """

    result = ''

    while True:
        char = read_char16(file)

        if char == '\x00':
            break

        result += char

    return result


def extract(arc_filename):
    """
    :param arc_filename:
    :type arc_filename: str
    :return:
    """

    with open(arc_filename, 'rb') as arc_file:
        file_count = read_unsigned_int32(arc_file)
        arc_file.seek(4, os.SEEK_CUR)  # header_length

        file_lengths = []
        file_names = []

        directory = os.path.splitext(arc_filename)[0]
        if not os.path.exists(directory):
            os.mkdir(directory)

        for i in range(0, file_count):
            file_lengths.append(read_unsigned_int32(arc_file))
            arc_file.seek(4, os.SEEK_CUR)  # file_offset
            file_names.append(os.path.join(directory, read_filename(arc_file)))

        for i in range(0, file_count):
            with open(file_names[i], 'wb+') as file_out:
                file_out.write(arc_file.read(file_lengths[i]))


def main():
    extract(sys.argv[1])


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.12966965112689102, 'fraction_numerical': 0.014201914171040445, 'mean_word_length': 2.3540372670807455, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '464278', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1102, 'n_words': 222}