<commit_before>var stream           = require('stream');
var util             = require('util');

function JSONStream() {
    stream.Transform.call(this, {objectMode: true});
}
util.inherits(JSONStream, stream.Transform);

JSONStream.prototype._transform = function (instance, __, done) {
    // if we've already started the stream, prefix a comma
    // if we haven't, prefix with a [ to start the array
    if (this.started) {
        this.push(',');
    } else {
        this.push('[');
        this.started = true;
    }
    // you can do whatever you need to do with the model
    // here, and then when you're finished
    // write the stringified model object
    if (instance != null) {
        this.push(JSON.stringify(instance));
    } else {
        this.push('');
    }
    done();
};


// end the json array
JSONStream.prototype._flush = function (done) {
    this.push(']');
    done();
};

module.exports = JSONStream;<commit_msg>send [] on _flush if not started<commit_after>var stream  = require('stream');
var util    = require('util');

function JSONStream() {
    stream.Transform.call(this, {objectMode: true});
}
util.inherits(JSONStream, stream.Transform);

JSONStream.prototype._transform = function (instance, __, done) {
    // if we've already started the stream, prefix a comma
    // if we haven't, prefix with a [ to start the array
    if (this.started) {
        this.push(',');
    } else {
        this.push('[');
        this.started = true;
    }
    // you can do whatever you need to do with the model
    // here, and then when you're finished
    // write the stringified model object
    if (instance != null) {
        this.push(JSON.stringify(instance));
    } else {
        this.push('');
    }
    done();
};


// end the json array
JSONStream.prototype._flush = function (done) {
    if (!this.started) {
        this.push('[]');
    } else {
        this.push(']');
    }
    done();
};

module.exports = JSONStream;
{'fraction_non_alphanumeric': 0.14358452138492872, 'fraction_numerical': 0.0, 'mean_word_length': 2.527827648114901, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1927846', 'n_tokens_mistral': 590, 'n_tokens_neox': 573, 'n_words': 174}