Skip to content

Commit

Permalink
[minor] Also send the raw message in the packet
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Oct 23, 2014
1 parent 7c629d2 commit 7b50af5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions spark.js
Expand Up @@ -303,7 +303,7 @@ Spark.readable('__initialise', [function initialise() {
* @api public
*/
Spark.readable('transforms', function transforms(primus, connection, type, data, raw) {
var packet = { data: data }
var packet = { data: data, raw: raw }
, fns = primus.transformers[type];

//
Expand Down Expand Up @@ -340,11 +340,13 @@ Spark.readable('transforms', function transforms(primus, connection, type, data,
//
// We always emit 2 arguments for the data event, the first argument is the
// parsed data and the second argument is the raw string that we received.
// This allows you, for exampele, to do some validation on the parsed data
// This allows you, for example, to do some validation on the parsed data
// and then save the raw string in your database without the stringify
// overhead.
//
if ('incoming' === type) return connection.emit('data', packet.data, raw);
if ('incoming' === type) {
return connection.emit('data', packet.data, packet.raw);
}

connection._write(packet.data);
}));
Expand Down

0 comments on commit 7b50af5

Please sign in to comment.