Comparing version 0.1.1 to 0.2.0
@@ -115,8 +115,8 @@ // Based on https://github.com/mranney/node_redis/blob/master/multi_bench.js | ||
tests.get_small_buf = [['get', 'rpbench_small_str'], {return_buffers: true}] | ||
tests.get_large_str = [['get', 'rpbench_large_str']] | ||
tests.get_large_str = [['get', 'rpbench_large_str'], {num_requests: 2e5}] | ||
tests.get_large_buf = [['get', 'rpbench_large_str'], {return_buffers: true}] | ||
tests.incr = [['incr', 'rpbench_counter']] | ||
tests.lpush = [['lpush', "rpbench_list", '1234']] | ||
tests.lrange10 = [['lrange', "rpbench_lrange", '0', '9']] | ||
tests.lrange100 = [['lrange', "rpbench_lrange", '0', '99']] | ||
tests.lrange10 = [['lrange', "rpbench_list", '0', '9'], {num_requests: 2e5}] | ||
tests.lrange100 = [['lrange', "rpbench_list", '0', '99'], {num_requests: 5e4}] | ||
@@ -137,3 +137,3 @@ | ||
socket.on('end', function() { | ||
socket.on('close', function() { | ||
runTests(Object.keys(tests)) | ||
@@ -140,0 +140,0 @@ }) |
{ | ||
"name": "redisparse", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Streaming Redis response parser", | ||
@@ -28,5 +28,5 @@ "main": "parser.js", | ||
"JSONStream": "~0.4.2", | ||
"v8-profiler": "~3.6.2-1", | ||
"v8-profiler": "git://github.com/tonsitiigi/v8-profiler.git#remove-heap-profiler", | ||
"archy": "0.0.2" | ||
} | ||
} |
var EventEmitter = require('events').EventEmitter | ||
var inherits = require('util').inherits | ||
var StringDecoder = require('string_decoder').StringDecoder | ||
var ArrayDecoder = require('array_decoder').ArrayDecoder | ||
@@ -15,6 +14,5 @@ | ||
function Parser(options) { | ||
this.name = exports.name | ||
this.options = options || {} | ||
this._state = START | ||
this._offset = 0 | ||
this._data = null | ||
this._line = '' | ||
@@ -27,3 +25,4 @@ this._cr = false | ||
this.options.return_buffers ? 'buffer' : 'string') | ||
this._string_decoder = new StringDecoder | ||
this._string_decoder = null | ||
this._is_string_decoder = false | ||
} | ||
@@ -40,10 +39,9 @@ inherits(Parser, EventEmitter) | ||
Parser.prototype.execute = function (data) { | ||
this._data = data | ||
this._offset = Math.min(this._skip, this._data.length) | ||
this._skip -= this._offset | ||
var offset = Math.min(this._skip, data.length) | ||
this._skip -= offset | ||
while (this._offset < this._data.length) { | ||
while (offset < data.length) { | ||
if (this._state === START) { | ||
this._line = '' | ||
switch (this._data[this._offset++]) { | ||
switch (data[offset++]) { | ||
case 43: // + | ||
@@ -69,4 +67,4 @@ this._state = SINGLE | ||
else if (this._state === BULK_DATA) { | ||
if (this._data.length - this._offset < this._size) { // Partial. | ||
var buffer = this._data.slice(this._offset) | ||
if (data.length - offset < this._size) { // Partial. | ||
var buffer = data.slice(offset) | ||
if (this.options.return_buffers) { | ||
@@ -76,22 +74,53 @@ this._reply_partial(buffer) | ||
else { | ||
if (!this._string_decoder) { | ||
this._string_decoder = new (require('string_decoder').StringDecoder) | ||
} | ||
this._is_string_decoder = true | ||
this._reply_partial(this._string_decoder.write(buffer)) | ||
} | ||
this._size -= this._data.length - this._offset | ||
this._offset = this._data.length | ||
this._size -= data.length - offset | ||
offset = data.length | ||
} | ||
else { | ||
buffer = this._data.slice(this._offset, this._offset += this._size) | ||
if (this.options.return_buffers) { | ||
this._reply(buffer) | ||
this._reply(data.slice(offset, offset += this._size)) | ||
} | ||
else { | ||
this._reply(this._string_decoder.write(buffer)) | ||
if (this._is_string_decoder) { | ||
this._is_string_decoder = false | ||
this._reply(this._string_decoder.write( | ||
data.slice(offset, offset += this._size))) | ||
} | ||
else { | ||
this._reply(data.parent.utf8Slice( | ||
offset + data.offset, | ||
(offset += this._size) + data.offset)) | ||
} | ||
} | ||
this._offset += 2 | ||
if (this._offset > this._data.length) { | ||
this._skip = this._offset - this._data.length | ||
offset += 2 | ||
if (offset > data.length) { | ||
this._skip = offset - data.length | ||
} | ||
} | ||
} | ||
else if (this._untilCRLF()) { | ||
else { | ||
if (this._cr && data[offset] === 0xa) { | ||
this._cr = false | ||
this._line = this._line.substring(0, this._line.length - 1) // Remove buffered <CR> | ||
offset++ | ||
} | ||
else { | ||
this._cr = false | ||
while (data[offset] !== 0xd || data[offset + 1] !== 0xa) { | ||
this._line += String.fromCharCode(data[offset]) | ||
if (offset + 1 === data.length) { // No more data. | ||
if (data[offset] === 0x0d) this._cr = true // Remember last <CR> | ||
return | ||
} | ||
offset++ | ||
} | ||
offset += 2 | ||
} | ||
if (this._state === SINGLE) { | ||
@@ -159,23 +188,2 @@ this._reply(this._line) | ||
Parser.prototype._untilCRLF = function () { | ||
if (this._cr && this._data[this._offset] === 0xa) { | ||
this._cr = false | ||
this._line = this._line.substring(0, this._line.length - 1) // Remove buffered <CR> | ||
this._offset++ | ||
} | ||
else { | ||
while (this._data[this._offset] !== 0xd || this._data[this._offset + 1] !== 0xa) { | ||
this._line += String.fromCharCode(this._data[this._offset]) | ||
this._offset++ | ||
if (this._offset === this._data.length) { // No more data. | ||
if (this._data[this._offset - 1] === 0xd) this._cr = true // Remember last <CR> | ||
return | ||
} | ||
} | ||
this._offset += 2 | ||
} | ||
return this._line | ||
} | ||
function Multibulk(count, parent) { | ||
@@ -182,0 +190,0 @@ this.count = count |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
4
3
59501
30
1207