Created
February 14, 2012 15:03
-
-
Save mmalecki/1827416 to your computer and use it in GitHub Desktop.
Sort of.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'), | |
Stream = require('stream'); | |
var FastJSONStream = exports.FastJSONStream = function (options) { | |
this.bufferSize = options.bufferSize; | |
this._buffer = new Buffer(this.bufferSize); | |
}; | |
util.inherits(FastJSONStream, Stream); | |
FastJSONStream.prototype.write = function (chunk) { | |
var data; | |
chunk.copy(this._buffer, this._buffer.length); | |
try { | |
this.emit('data', JSON.parse(this._buffer)); | |
this._buffer = new Buffer(this.bufferSize); | |
} | |
catch (_) {} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment