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

function SigningStream(openpgp, boundary) {
  stream.Stream.call(this);
  this.writable = true;
  this.buffer = "";
  this.openpgp = openpgp;
  this.boundary = boundary;
};
util.inherits(SigningStream, stream.Stream);

SigningStream.prototype.write = function(data) {
  if (data && data.length)
    this.buffer += data.toString();
};

SigningStream.prototype.end = function(data) {
  this.write(data);
  this.emit('end');
};

SigningStream.prototype.sign = function(callback) {
  var that = this;
  process.nextTick(function () {
    var body = that.buffer.replace(/\r\n/g, '\n').replace(/\n/g, '\r\n');
    var ciphertext = that.openpgp.write_signed_message(that.openpgp.keyring.privateKeys[0].obj, body);
    var ciphertext = ciphertext.substring(ciphertext.lastIndexOf('-----BEGIN PGP SIGNATURE-----'));
    var body = '';
    body += '--' + that.boundary + '\n';
    body += that.buffer + '\n\n';
    body += '--' + that.boundary + '\n';
    body += 'Content-Type: application/pgp-signature\n\n';<commit_msg>Automatically escape ----BEGIN PGP messages<commit_after>var stream = require('stream');
var util = require('util');

function SigningStream(openpgp, boundary) {
  stream.Stream.call(this);
  this.writable = true;
  this.buffer = "";
  this.openpgp = openpgp;
  this.boundary = boundary;
};
util.inherits(SigningStream, stream.Stream);

SigningStream.prototype.write = function(data) {
  if (data && data.length)
    this.buffer += data.toString();
};

SigningStream.prototype.end = function(data) {
  this.write(data);
  this.emit('end');
};

SigningStream.prototype.sign = function(callback) {
  var that = this;
  process.nextTick(function () {
    var body = that.buffer.replace(/\r\n/g, '\n').replace(/\n/g, '\r\n');
    var cleaned = body;
    cleaned = cleaned.replace(/-----BEGIN PGP(.*)-----\r\n/g, 'BEGIN PGP$1\r\n');
    cleaned = cleaned.replace(/-----END PGP(.*)-----\r\n/g, 'END PGP$1\r\n');
    var ciphertext = that.openpgp.write_signed_message(that.openpgp.keyring.privateKeys[0].obj, cleaned);
    var ciphertext = ciphertext.substring(ciphertext.lastIndexOf('-----BEGIN PGP SIGNATURE-----'));
    var body = '';
    body += '--' + that.boundary + '\n';
    body += cleaned + '\n\n';
    body += '--' + that.boundary + '\n';
    body += 'Content-Type: application/pgp-signature\n\n';
{'fraction_non_alphanumeric': 0.19799079112599413, 'fraction_numerical': 0.0016743407283382169, 'mean_word_length': 3.5265151515151514, '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': '2047473', 'n_tokens_mistral': 833, 'n_tokens_neox': 812, 'n_words': 144}