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

antena

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antena - npm Package Compare versions

Comparing version 4.0.4 to 4.0.5

73

lib/node/messaging.js

@@ -6,4 +6,3 @@

socket._antena_buffer = Buffer.allocUnsafe(1024);
socket._antena_current = 0;
socket._antena_target = Infinity;
socket._antena_length = 0;
socket._antena_send = send;

@@ -25,43 +24,43 @@ socket.on("data", ondata);

function ondata (buffer) {
if (this._antena_current === 0) {
if (buffer.length < 4) {
buffer.copy(this._antena_buffer);
this._antena_current = buffer.length;
} else {
const bytelength = buffer.readUInt32LE(0);
if (buffer.length >= bytelength) {
this._antena_receive(buffer.toString("utf8", 4, bytelength));
if (buffer.length > bytelength) {
ondata.call(this, buffer.slice(bytelength));
}
} else {
if (buffer.length >= this._antena_buffer.length) {
this._antena_buffer = buffer;
} else {
buffer.copy(this._antena_buffer);
}
this._antena_current = buffer.length;
this._antena_target = bytelength;
debugger;
while (buffer.length) {
// Not enough data to compute the message's bytelength
if (this._antena_length + buffer.length < 4) {
buffer.copy(this._antena_buffer, this._antena_length);
this._antena_length += buffer.length;
break;
}
// Optimization when the antena buffer is empty
if (this._antena_length === 0) {
const target = buffer.readUInt32LE(0);
if (buffer.length >= target) {
this._antena_receive(buffer.toString("utf8", 4, target));
buffer = buffer.slice(target);
continue;
}
}
} else {
if (this._antena_buffer.length < this._antena_current + buffer.length) {
// Make sure the antena buffer has enough byte to read the message's bytelength
if (this._antena_length < 4) {
buffer.copy(this._antena_buffer, this._antena_length, 0, 4 - this._antena_length);
buffer = buffer.slice(4 - this._antena_length);
this._antena_length = 4;
}
// Read the message's bytelength
const target = this._antena_buffer.readUInt32LE(0);
// Copy the part of the input buffer that is still in the current message boundary
const tocopy = Math.min(buffer.length, target - this._antena_length);
if (this._antena_buffer.length < target + tocopy) {
const temporary = this._antena_buffer;
this._antena_buffer = Buffer.allocUnsafe(this._antena_current + buffer.length);
temporary.copy(this._antena_buffer);
this._antena_buffer = Buffer.allocUnsafe(target + tocopy);
temporary.copy(this._antena_buffer, 0, 0, this._antena_length);
}
buffer.copy(this._antena_buffer, this._antena_current);
this._antena_current += buffer.length;
if (this._antena_current >= 4 && this._antena_current - buffer.length < 4) {
this._antena_target = this._antena_buffer.readUInt32LE(0);
buffer.copy(this._antena_buffer, this._antena_length, 0, tocopy);
buffer = buffer.slice(tocopy);
this._antena_length += tocopy;
// We reached the message boundary
if (this._antena_length === target) {
this._antena_receive(this._antena_buffer.toString("utf8", 4, target));
this._antena_length = 0;
}
if (this._antena_current >= this._antena_target) {
this._antena_receive(this._antena_buffer.toString("utf8", 4, this._antena_target));
this._antena_current = 0;
this._antena_target = Infinity;
if (this._antena_current > this._antena_target) {
ondata.call(this, this._antena_buffer.slice(this._antena_target, this._antena_current));
}
}
}
}
{
"name": "antena",
"description": "Isomorphic communication library for node and browsers",
"version": "4.0.4",
"version": "4.0.5",
"author": {

@@ -6,0 +6,0 @@ "name": "Laurent Christophe",

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