<commit_before>
var es = require('event-stream');

var cred = {
    app:require('../../config/app'),
    user:require('../../config/user')
};


exports = module.exports = function (p) {
    return {
        // retrieve all of the lists defined for your user account
        0: function () {
            p.query()
                .select('lists/list')
                .auth(cred.user.mailchimp.apikey)
                .request(function (err, res, body) {
                    debugger;
                    if (err) console.log(err);
                    console.log(body);
                });
        },
        // export contacts from a list
        1: function () {
            p.query('export')
                .select('list')
                .where({id:'bd0b216f1c'})
                .auth(cred.user.mailchimp.apikey)
                .request(function (err, res, body) {
                    debugger;
                    if (err) console.log(err);
                    console.log(body);
                });
        },
        // stream contacts from a list
        2: function () {
            p.query('export')
                .select('list')
                .where({id:'bd0b216f1c'})
                .auth(cred.user.mailchimp.apikey)
                .request()
                .pipe(es.split())
                .pipe(es.map(function (data, done) {
                    console.log(data);
                    console.log('---------------------');
                    done();
                }));
        }
    };
}<commit_msg>Add on end stream event<commit_after>
var es = require('event-stream');

var cred = {
    app:require('../../config/app'),
    user:require('../../config/user')
};


exports = module.exports = function (p) {
    return {
        // retrieve all of the lists defined for your user account
        0: function () {
            p.query()
                .select('lists/list')
                .auth(cred.user.mailchimp.apikey)
                .request(function (err, res, body) {
                    debugger;
                    if (err) console.log(err);
                    console.log(body);
                });
        },
        // export contacts from a list
        1: function () {
            p.query('export')
                .select('list')
                .where({id:'<KEY>'})
                .auth(cred.user.mailchimp.apikey)
                .request(function (err, res, body) {
                    debugger;
                    if (err) console.log(err);
                    console.log(body);
                });
        },
        // stream contacts from a list
        2: function () {
            p.query('export')
                .select('list')
                .where({id:'bd0b216f1c'})
                .auth(cred.user.mailchimp.apikey)
                .request()
                .pipe(es.split())
                .pipe(es.map(function (data, done) {
                    console.log(data);
                    console.log('---------------------');
                    done();
                }))
                .on('end', function (e) {
                    console.log('DONE!');
                });
        }
    };
}
{'fraction_non_alphanumeric': 0.1527514231499051, 'fraction_numerical': 0.006641366223908918, 'mean_word_length': 1.0393294648613798, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '495671', 'n_tokens_mistral': 869, 'n_tokens_neox': 806, 'n_words': 160}