Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

beanstalkd-protocol

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beanstalkd-protocol - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

17

lib/index.js

@@ -98,3 +98,3 @@ 'use strict';

let remainder = buffer.length > boundary + _misc.CRLF.length ? buffer.slice(boundary + _misc.CRLF.length) : null;
let args;
let args = parts[0];

@@ -110,16 +110,17 @@ if (!spec) {

if (spec.parts.length > 1) {
for (let i = 0; i < spec.parts.length - 1; i++) {
for (let i = 1; i < spec.parts.length; i++) {
if (!remainder) return [buffer, null];
let previous = i && spec.parts[i - 1] || null;
let bytes = previous[previous.length - 1] === 'bytes' && args[args.length - 1] || null;
let boundary = remainder.indexOf(_misc.CRLF);
if (bytes > remainder.length) return [buffer, null];
let boundary = bytes || remainder.indexOf(_misc.CRLF);
if (boundary === -1) return [buffer, null];
// TODO: Support non buffer args
parts.push(remainder.slice(0, boundary));
let part = remainder.slice(0, boundary);
remainder = remainder.length > boundary + _misc.CRLF.length ? buffer.slice(remainder + _misc.CRLF.length) : null;
args.push(part);
}
args = Array.prototype.concat.apply([], parts);
} else {
args = parts[0];
}

@@ -126,0 +127,0 @@

{
"name": "beanstalkd-protocol",
"version": "0.2.1",
"version": "0.2.2",
"description": "Beanstalkd protocol parser for Node.js/Javascript",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -48,2 +48,10 @@ import BeanstalkdProtocol, {convertArgs} from '../../src/index';

if (spec.args.indexOf('bytes') !== -1) {
if (array) {
args[spec.args.indexOf('bytes')] = args[spec.args.indexOf('data')].length;
} else {
args.bytes = args.data.length;
}
}
return args;

@@ -50,0 +58,0 @@ }

@@ -83,2 +83,63 @@ import BeanstalkdProtocol from '../../src/index';

it('parses large RESERVED reply', function () {
let values = {};
for (let i = 0; i < 10000; i++) {
values[Math.random().toString()] = Math.random().toString();
}
let data = new Buffer(JSON.stringify(values));
let full = Buffer.concat([
new Buffer(`RESERVED 1337 ${data.length}`),
CRLF,
data,
CRLF
]);
let buffers = [
full.slice(0, 200000),
full.slice(200000)
];
let [remainder, result] = protocol.parseReply(buffers[0]);
expect(result, 'to equal', null);
expect(remainder.length, 'to equal', buffers[0].length);
expect(
protocol.parseReply(Buffer.concat([remainder, buffers[1]])),
'to equal',
[null, {
reply: 'RESERVED',
args: {
id: 1337,
bytes: data.length,
data: data
}
}]
);
});
it('parses RESERVED reply containg CRLF', function () {
let data = new Buffer('yolo\r\nyolo');
let buffer = Buffer.concat([
new Buffer(`RESERVED 1234 ${data.length}`),
CRLF,
data,
CRLF
]);
expect(
protocol.parseReply(buffer),
'to equal',
[null, {
reply: 'RESERVED',
args: {
id: 1234,
bytes: data.length,
data: data
}
}]
);
});
it('parses multiple replies in buffer', function () {

@@ -85,0 +146,0 @@ let tube = Math.random().toString();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc