Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
user-stream.js
response.on('data', function(chunk) {
data += chunk.toString('utf8');
//is heartbeat?
if (data == '\r\n') {
stream.emit('heartbeat');
return;
}
var index, json;
while((index = data.indexOf('\r\n')) > -1) {
json = data.slice(0, index);
data = data.slice(index + 2);
if(json.length > 0) {
try {
stream.emit('data', JSON.parse(json));
} catch(e) {
stream.emit('garbage', data);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.