<commit_before>/**
 * @module storj-bridge/utils
 */

'use strict';

var through = require('through');

/**
 * Returns a transform stream that wraps objects written to it
 * in proper JSON array string
 */
module.exports.createArrayFormatter = function(transformer) {
  return through(function(entry) {
    if (!this._openBracketWritten) {
      this.queue('[');
      this._openBracketWritten = true;
    }

    if (this._needsPrecedingComma) {
      this.queue(',');
    } else {
      this._needsPrecedingComma = true;
    }

    this.queue(JSON.stringify(transformer(entry)));
  }, function() {
    this.queue(']');
    this.queue(null);
  });
};
<commit_msg>fix json response of GET `/buckets/:id/files` when there are no files<commit_after>/**
 * @module storj-bridge/utils
 */

'use strict';

var through = require('through');

/**
 * Returns a transform stream that wraps objects written to it
 * in proper JSON array string
 */
module.exports.createArrayFormatter = function(transformer) {
  return through(function(entry) {
    if (!this._openBracketWritten) {
      this.queue('[');
      this._openBracketWritten = true;
    }

    if (this._needsPrecedingComma) {
      this.queue(',');
    } else {
      this._needsPrecedingComma = true;
    }

    this.queue(JSON.stringify(transformer(entry)));
  }, function() {
    if (!this._openBracketWritten) {
      this.queue('[');
    }
    this.queue(']');
    this.queue(null);
  });
};

{'fraction_non_alphanumeric': 0.1526243093922652, 'fraction_numerical': 0.0, 'mean_word_length': 3.2244897959183674, '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': '4897534', 'n_tokens_mistral': 468, 'n_tokens_neox': 452, 'n_words': 97}