<commit_before>SyncFS = (function () {
    "use strict";

    var ID3V1_START = "TAG";
    var NULLSTRING = String.fromCharCode(0);

    var pendingDownloads = []; // список URL скачиваемых файлов
    var downloadedFilesIds = []; // список ID скачанных файлов
    var cachedCounter = -1;

    chrome.syncFileSystem.onFileStatusChanged.addListener(function (details) {
        if (details.direction !== "remote_to_local")
            return;

        cachedCounter = -1;
        updateCurrentCounter();
    });

    chrome.runtime.onMessage.addListener(function (req, sender, sendResponse) {
        if (req.action === "currentSyncFSCounter") {
            sendResponse(SyncFS.getCurrentCounterValue());
        } else if (req.action === "saveGoogleDrive") {
            SyncFS.save(req.artist, req.title, req.url, req.id);
        }
    });


    /**
     * Создание безопасной строки длиной bytesLength байт
     *
     * @param {String} str
     * @param {Number} bytesLength
     * @return {String}
     */
    function makeSafeString(str, bytesLength) {
        var output = "";
        var nullString = String.fromCharCode(0);
        var index = 0;
        var totalBytesLength = 0;
        var code, bytes;

        while (totalBytesLength < bytesLength) {
            if (index === -1 || index >= str.length) {
                output += nullString;
                totalBytesLength += 1;
            } else {
                code = str.charCodeAt(index);

                if (code < 128) { // 1 byte
                    output += str[index];

                    index += 1;
                    totalBytesLength += 1;
                } else {
                    bytes = (code >= 128 && code < 2048) ? 2 : 3;

                    if (totalBytesLength + bytes > bytesLength) { // когда сумма не вмещается в 30 байт, не добавляем символ
                        index = -1;
                    } else {
                        output += str[index];

                        index += 1;
                        totalBytesLength += bytes;
                    }
                }
            }
        }

        return output;
    }

    function readBinary(blob, callback) {
        var reader = new FileReader;
        reader.onloadend = function () {
            callback(reader.result);
        };

        reader.readAsBinaryString(blob);
    }

    function updateCurrentCounter() {
        chrome.syncFileSystem.requestFileSystem(function (fs) {
            var dirReader = fs.root.createReader();

            dirReader.readEntries(function (results) {
                cachedCounter = 0;
                downloadedFilesIds.length = 0;

                var tasks = [];<commit_msg>Reminder for syncFileSystem<commit_after>SyncFS = (function () {
    "use strict";

    var ID3V1_START = "TAG";
    var NULLSTRING = String.fromCharCode(0);

    var pendingDownloads = []; // список URL скачиваемых файлов
    var downloadedFilesIds = []; // список ID скачанных файлов
    var cachedCounter = -1;

    chrome.syncFileSystem.onFileStatusChanged.addListener(function (details) {
        if (details.direction !== "remote_to_local")
            return;

        cachedCounter = -1;
        updateCurrentCounter();
    });

    chrome.runtime.onMessage.addListener(function (req, sender, sendResponse) {
        if (req.action === "currentSyncFSCounter") {
            sendResponse(SyncFS.getCurrentCounterValue());
        } else if (req.action === "saveGoogleDrive") {
            SyncFS.save(req.artist, req.title, req.url, req.id);
        }
    });


    /**
     * Создание безопасной строки длиной bytesLength байт
     *
     * @param {String} str
     * @param {Number} bytesLength
     * @return {String}
     */
    function makeSafeString(str, bytesLength) {
        var output = "";
        var nullString = String.fromCharCode(0);
        var index = 0;
        var totalBytesLength = 0;
        var code, bytes;

        while (totalBytesLength < bytesLength) {
            if (index === -1 || index >= str.length) {
                output += nullString;
                totalBytesLength += 1;
            } else {
                code = str.charCodeAt(index);

                if (code < 128) { // 1 byte
                    output += str[index];

                    index += 1;
                    totalBytesLength += 1;
                } else {
                    bytes = (code >= 128 && code < 2048) ? 2 : 3;

                    if (totalBytesLength + bytes > bytesLength) { // когда сумма не вмещается в 30 байт, не добавляем символ
                        index = -1;
                    } else {
                        output += str[index];

                        index += 1;
                        totalBytesLength += bytes;
                    }
                }
            }
        }

        return output;
    }

    function readBinary(blob, callback) {
        var reader = new FileReader;
        reader.onloadend = function () {
            callback(reader.result);
        };

        reader.readAsBinaryString(blob);
    }

    function updateCurrentCounter() {
        // @todo use http://developer.chrome.com/apps/syncFileSystem.html#method-getServiceStatus

        chrome.syncFileSystem.requestFileSystem(function (fs) {
            if (!fs)
                return;

            var dirReader = fs.root.createReader();

            dirReader.readEntries(function (results) {
                cachedCounter = 0;
                downloadedFilesIds.length = 0;

                var tasks = [];
{'fraction_non_alphanumeric': 0.10669795992056327, 'fraction_numerical': 0.011193356201480412, 'mean_word_length': 1.5648148148148149, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2209510', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1487, 'n_words': 340}