Permalink
Browse files

Support multiline strings in data

  • Loading branch information...
1 parent c22f01d commit 2c7449e31be925015ccacaf55961be4d6a214ef0 @aslakhellesoy aslakhellesoy committed Nov 3, 2011
Showing with 7 additions and 2 deletions.
  1. +7 −2 eventstream.js
View
@@ -53,7 +53,12 @@ module.exports.EventStream = function(req, res) {
opts.value = (typeof opts.encode === 'function')
? opts.encode(opts.value)
: this.encode(opts.value);
- res.write(opts.field + ': ' + opts.value + '\n');
+ opts.value.split("\n").forEach(function(line) {
+ res.write(opts.field + ': ' + line + '\n');
+ });
+ if(opts.field == 'data') {
+ res.write('\n');
+ }
};
/**
@@ -127,7 +132,7 @@ module.exports.EventStream.prototype.sendEvent = function(event) {
module.exports.EventStream.prototype.sendData = function(data) {
return this.send({
field: 'data',
- value: data + '\n'
+ value: data
});
};

0 comments on commit 2c7449e

Please sign in to comment.