<commit_before>/*
  GIFEncoder.js

  Authors
  <NAME> (original Java version - <EMAIL>)
  <NAME> (AS3 version - bytearray.org)
  <NAME> (JS version - <EMAIL>)
  <NAME> (Implemented streams - <EMAIL>)
*/

var assert = require('assert');
var EventEmitter = require('events').EventEmitter;
var ReadableStream = require('readable-stream');
var util = require('util');

var NeuQuant = require('./TypedNeuQuant.js');
var LZWEncoder = require('./LZWEncoder.js');

// DEV: By using a capacitor, we prevent creating a data event for every byte written
function ByteCapacitor(options) {
  // Inherit from ReadableStream
  ReadableStream.call(this, options);
  this.resetData();
}
util.inherits(ByteCapacitor, ReadableStream);

ByteCapacitor.prototype._read = function () {
  // The output is controlled by the input provided by methods.
  // If we exceed the highwater mark, we will raise an error.
  this.okayToPush = true;
};

ByteCapacitor.prototype.resetData = function () {
  this.data = [];
};

ByteCapacitor.prototype.flushData = function () {
  // If we are not okay to push, emit an error
  if (!this.okayToPush) {
    return this.emit('error', new Error('GIF memory limit exceeded. Please `read` from GIF before writing additional frames/information.');
  }

  // Otherwise, push out the new buffer
  var buff = new Buffer(this.data);
  this.resetData();
  this.okayToPush = this.push(buff);
};

ByteCapacitor.prototype.writeByte = function (val) {
  this.data.push(val);
};
<commit_msg>Breaking apart error line to make slightly shorter<commit_after>/*
  GIFEncoder.js

  Authors
  <NAME> (original Java version - <EMAIL>)
  <NAME> (AS3 version - bytearray.org)
  <NAME> (JS version - <EMAIL>)
  <NAME> (Implemented streams - <EMAIL>)
*/

var assert = require('assert');
var EventEmitter = require('events').EventEmitter;
var ReadableStream = require('readable-stream');
var util = require('util');

var NeuQuant = require('./TypedNeuQuant.js');
var LZWEncoder = require('./LZWEncoder.js');

// DEV: By using a capacitor, we prevent creating a data event for every byte written
function ByteCapacitor(options) {
  // Inherit from ReadableStream
  ReadableStream.call(this, options);
  this.resetData();
}
util.inherits(ByteCapacitor, ReadableStream);

ByteCapacitor.prototype._read = function () {
  // The output is controlled by the input provided by methods.
  // If we exceed the highwater mark, we will raise an error.
  this.okayToPush = true;
};

ByteCapacitor.prototype.resetData = function () {
  this.data = [];
};

ByteCapacitor.prototype.flushData = function () {
  // If we are not okay to push, emit an error
  if (!this.okayToPush) {
    var err = new Error('GIF memory limit exceeded. Please `read` from GIF before writing additional frames/information.');
    return this.emit('error', err);
  }

  // Otherwise, push out the new buffer
  var buff = new Buffer(this.data);
  this.resetData();
  this.okayToPush = this.push(buff);
};

ByteCapacitor.prototype.writeByte = function (val) {
  this.data.push(val);
};

{'fraction_non_alphanumeric': 0.13097987462883537, 'fraction_numerical': 0.0006598482349059716, 'mean_word_length': 4.138983050847457, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3901463', 'n_tokens_mistral': 948, 'n_tokens_neox': 941, 'n_words': 284}