Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Forked from mmalecki/fast-json-stream.js
Created February 14, 2012 15:11
Show Gist options
  • Save heapwolf/1827462 to your computer and use it in GitHub Desktop.
Save heapwolf/1827462 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.lenght);
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