Skip to content

Instantly share code, notes, and snippets.

@mmalecki
Created February 14, 2012 15:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mmalecki/1827416 to your computer and use it in GitHub Desktop.
Save mmalecki/1827416 to your computer and use it in GitHub Desktop.
Sort of.
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