<commit_before>try { module.exports = {ftp:ftp}; } catch (e) { }

// N2O File Transfer Protocol

var ftp = {
    $file: undefined, $reader: undefined, $block: undefined, $offset: undefined,
    init: function(file, force) { ftp.$file = file; ftp.send('', 'init', 1); },
    start: function() { ftp.$active = true; ftp.send_slice(ftp.$offset, ftp.$offset + ftp.$block); },
    stop: function() { ftp.$active = false; },
    send: function(data, status, force) {
        ws.send(enc(tuple(atom('ftp'),bin(co(session)), bin(ftp.$file.name), number(3),number(4),number(5),number(6),
        number(ftp.$file.size),bin(data),bin(status||'send'),number(force || data.byteLength),number(11)))); },
    send_slice: function(start, end) {
        this.$reader = new FileReader();
        this.$reader.onloadend=function(e) {
             var res=e.target, data=e.target.result;
             if(res.readyState==FileReader.DONE&&data.byteLength>0) ftp.send(data); };
        this.$reader.readAsArrayBuffer(ftp.$file.slice(start,end)); } }

$file.do = function(rsp) {
    var offset = rsp.v[6].v, block = rsp.v[10].v, status = rsp.v[9].v;
    switch (status) { case 'init': ftp.$offset = offset; ftp.$block = block; break;
                      case 'send': var x = qi('ftp_status'); if(x) x.innerHTML = offset;
                                   if(block>0 && ftp.$active) ftp.send_slice(offset, offset+block); } }<commit_msg>Binary data should be decoded in string data<commit_after>try { module.exports = {ftp:ftp}; } catch (e) { }

// N2O File Transfer Protocol

var ftp = {
    $file: undefined, $reader: undefined, $block: undefined, $offset: undefined, $autostart: undefined,
    init: function(file, autostart) { ftp.$file=file; ftp.$autostart=autostart; ftp.send('', 'init', 1); },
    start: function() { ftp.$active = true; ftp.send_slice(ftp.$offset, ftp.$offset + ftp.$block); },
    stop: function() { ftp.$active = false; },
    send: function(data, status, block) {
        ws.send(enc(tuple(atom('ftp'),bin(co(session)), bin(ftp.$file.name), number(3),number(4),number(5),number(6),
        number(ftp.$file.size),bin(data),bin(status||'send'),number(block || data.byteLength),number(11)))); },
    send_slice: function(start, end) {
        this.$reader = new FileReader();
        this.$reader.onloadend=function(e) {
             var res=e.target, data=e.target.result;
             if(res.readyState==FileReader.DONE&&data.byteLength>0) ftp.send(data); };
        this.$reader.readAsArrayBuffer(ftp.$file.slice(start,end)); } }

$file.do = function(rsp) {
    var offset = rsp.v[6].v, block = rsp.v[10].v, status = utf8_dec(rsp.v[9].v);
    switch (status) {
        case 'init': ftp.$offset = offset; ftp.$block = block; if(ftp.$autostart) ftp.start(); break;
        case 'send': var x = qi('ftp_status'); if(x) x.innerHTML = offset;
           if(block>0 && ftp.$active) ftp.send_slice(offset, offset+block); break;
        case 'relay': if (typeof ftp.relay === 'function') ftp.relay(rsp); break;
    }
};
{'fraction_non_alphanumeric': 0.19383697813121273, 'fraction_numerical': 0.009609012591119947, 'mean_word_length': 3.519461077844311, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6735970', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1033, 'n_words': 200}