<commit_before>/* jshint esversion: 6, node: true */
const Fs = require('fs');
const nThen = require('nthen');
const Pinned = require('./pinned');
const Nacl = require('tweetnacl/nacl-fast');
const Path = require('path');
const Pins = require('../lib/pins');
const Config = require('../lib/load-config');

var escapeKeyCharacters = function (key) {
    return key && key.replace && key.replace(/\//g, '-');
};


const dataIdx = process.argv.indexOf('--data');
let edPublic;
if (dataIdx === -1) {
    const hasEdPublic = process.argv.indexOf('--ed');
    if (hasEdPublic === -1) { return void console.error("Missing ed argument"); }
    edPublic = escapeKeyCharacters(process.argv[hasEdPublic+1]);
} else {
    const deleteData = JSON.parse(process.argv[dataIdx+1]);
    if (!deleteData.toSign || !deleteData.proof) { return void console.error("Invalid arguments"); }
    // Check sig
    const ed = Nacl.util.decodeBase64(deleteData.toSign.edPublic);
    const signed = Nacl.util.decodeUTF8(JSON.stringify(deleteData.toSign));
    const proof = Nacl.util.decodeBase64(deleteData.proof);
    if (!Nacl.sign.detached.verify(signed, proof, ed)) { return void console.error("Invalid signature"); }
    edPublic = escapeKeyCharacters(deleteData.toSign.edPublic);
}

let data = [];
let pinned = [];

nThen((waitFor) => {
    var pinPath = Config.pinPath || './pins';

    let f = Path.join(pinPath, edPublic.slice(0, 2), edPublic + '.ndjson');
    Fs.readFile(f, waitFor((err, content) => {
        if (err) { throw err; }
        pinned = Pins.calculateFromLog(content.toString('utf8'), f);
    }));
}).nThen((waitFor) => {
    Pinned.load(waitFor((d) => {
        data = Object.keys(d);
    }), {
        exclude: [edPublic + '.ndjson']
    });
}).nThen(() => {<commit_msg>use correct function signature for Pinned.load<commit_after>/* jshint esversion: 6, node: true */
const Fs = require('fs');
const nThen = require('nthen');
const Pinned = require('./pinned');
const Nacl = require('tweetnacl/nacl-fast');
const Path = require('path');
const Pins = require('../lib/pins');
const Config = require('../lib/load-config');

var escapeKeyCharacters = function (key) {
    return key && key.replace && key.replace(/\//g, '-');
};


const dataIdx = process.argv.indexOf('--data');
let edPublic;
if (dataIdx === -1) {
    const hasEdPublic = process.argv.indexOf('--ed');
    if (hasEdPublic === -1) { return void console.error("Missing ed argument"); }
    edPublic = escapeKeyCharacters(process.argv[hasEdPublic+1]);
} else {
    const deleteData = JSON.parse(process.argv[dataIdx+1]);
    if (!deleteData.toSign || !deleteData.proof) { return void console.error("Invalid arguments"); }
    // Check sig
    const ed = Nacl.util.decodeBase64(deleteData.toSign.edPublic);
    const signed = Nacl.util.decodeUTF8(JSON.stringify(deleteData.toSign));
    const proof = Nacl.util.decodeBase64(deleteData.proof);
    if (!Nacl.sign.detached.verify(signed, proof, ed)) { return void console.error("Invalid signature"); }
    edPublic = escapeKeyCharacters(deleteData.toSign.edPublic);
}

let data = [];
let pinned = [];

nThen((waitFor) => {
    var pinPath = Config.pinPath || './pins';

    let f = Path.join(pinPath, edPublic.slice(0, 2), edPublic + '.ndjson');
    Fs.readFile(f, waitFor((err, content) => {
        if (err) { throw err; }
        pinned = Pins.calculateFromLog(content.toString('utf8'), f);
    }));
}).nThen((waitFor) => {
    Pinned.load(waitFor((err, d) => {
        data = Object.keys(d);
    }), {
        exclude: [edPublic + '.ndjson']
    });
}).nThen(() => {
{'fraction_non_alphanumeric': 0.18512304250559283, 'fraction_numerical': 0.00727069351230425, 'mean_word_length': 3.7820855614973263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4419925', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1158, 'n_words': 250}