<commit_before>/*!
 * easy-websocket
 * Copyright(c) 2011 <NAME> <<EMAIL>>
 * MIT Licensed
 */

var events = require('events')
  , util = require('util')
  , EventEmitter = events.EventEmitter;

/**
 * HyBi Receiver implementation
 */

function Receiver () {
  this.state = {
    activeFragmentedOperation: null,
    lastFragment: false,
    masked: false,
    opcode: 0
  };
  this.overflow = null;
  this.expectOffset = 0;
  this.expectBuffer = null;
  this.expectHandler = null;
  this.currentMessage = '';

  var self = this;  
  this.opcodeHandlers = {
    // text
    '1': function(data) {
      var finish = function(mask, data) {
        self.currentMessage += self.unmask(mask, data);
        if (self.state.lastFragment) {
          self.emit('text', self.currentMessage, {masked: self.state.masked});
          self.currentMessage = '';
        }<commit_msg>handle fragmented utf8 strings by delaying tostring<commit_after>/*!
 * easy-websocket
 * Copyright(c) 2011 <NAME> <<EMAIL>>
 * MIT Licensed
 */

var events = require('events')
  , util = require('util')
  , EventEmitter = events.EventEmitter;

/**
 * HyBi Receiver implementation
 */

function Receiver () {
  this.state = {
    activeFragmentedOperation: null,
    lastFragment: false,
    masked: false,
    opcode: 0
  };
  this.overflow = null;
  this.expectOffset = 0;
  this.expectBuffer = null;
  this.expectHandler = null;
  this.currentMessage = '';

  var self = this;  
  this.opcodeHandlers = {
    // text
    '1': function(data) {
      var finish = function(mask, data) {
        if (typeof self.currentMessage == 'string') self.currentMessage = []; // build a buffer list
        var packet = self.unmask(mask, data, true);
        if (packet != null) self.currentMessage.push(packet);
        if (self.state.lastFragment) {
          self.emit('text', self.concatBuffers(self.currentMessage).toString('utf8'), {masked: self.state.masked});
          self.currentMessage = '';
        }
{'fraction_non_alphanumeric': 0.140973630831643, 'fraction_numerical': 0.008113590263691683, 'mean_word_length': 2.946, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5766425', 'n_tokens_mistral': 621, 'n_tokens_neox': 607, 'n_words': 139}