Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Support multiline strings in data
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Nov 3, 2011
1 parent c22f01d commit 2c7449e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions eventstream.js
Expand Up @@ -53,7 +53,12 @@ module.exports.EventStream = function(req, res) {
opts.value = (typeof opts.encode === 'function') opts.value = (typeof opts.encode === 'function')
? opts.encode(opts.value) ? opts.encode(opts.value)
: this.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');
}
}; };


/** /**
Expand Down Expand Up @@ -127,7 +132,7 @@ module.exports.EventStream.prototype.sendEvent = function(event) {
module.exports.EventStream.prototype.sendData = function(data) { module.exports.EventStream.prototype.sendData = function(data) {
return this.send({ return this.send({
field: 'data', field: 'data',
value: data + '\n' value: data
}); });
}; };


Expand Down

0 comments on commit 2c7449e

Please sign in to comment.