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

engine.io-parser

Package Overview
Dependencies
Maintainers
2
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

engine.io-parser - npm Package Compare versions

Comparing version 5.0.7 to 5.1.0

3

build/cjs/decodePacket.browser.d.ts
import { Packet, BinaryType, RawData } from "./commons.js";
declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;
export default decodePacket;
export declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodePacket = void 0;
const commons_js_1 = require("./commons.js");

@@ -33,2 +34,3 @@ const base64_arraybuffer_js_1 = require("./contrib/base64-arraybuffer.js");

};
exports.decodePacket = decodePacket;
const decodeBase64Packet = (data, binaryType) => {

@@ -46,8 +48,21 @@ if (withNativeArrayBuffer) {

case "blob":
return data instanceof ArrayBuffer ? new Blob([data]) : data;
if (data instanceof Blob) {
// from WebSocket + binaryType "blob"
return data;
}
else {
// from HTTP long-polling or WebTransport
return new Blob([data]);
}
case "arraybuffer":
default:
return data; // assuming the data is already an ArrayBuffer
if (data instanceof ArrayBuffer) {
// from HTTP long-polling (base64) or WebSocket + binaryType "arraybuffer"
return data;
}
else {
// from WebTransport (Uint8Array)
return data.buffer;
}
}
};
exports.default = decodePacket;
import { Packet, BinaryType, RawData } from "./commons.js";
declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;
export default decodePacket;
export declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodePacket = void 0;
const commons_js_1 = require("./commons.js");

@@ -31,20 +32,29 @@ const decodePacket = (encodedPacket, binaryType) => {

};
exports.decodePacket = decodePacket;
const mapBinary = (data, binaryType) => {
const isBuffer = Buffer.isBuffer(data);
switch (binaryType) {
case "arraybuffer":
return isBuffer ? toArrayBuffer(data) : data;
if (data instanceof ArrayBuffer) {
// from WebSocket & binaryType "arraybuffer"
return data;
}
else if (Buffer.isBuffer(data)) {
// from HTTP long-polling
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
}
else {
// from WebTransport (Uint8Array)
return data.buffer;
}
case "nodebuffer":
default:
return data; // assuming the data is already a Buffer
if (Buffer.isBuffer(data)) {
// from HTTP long-polling or WebSocket & binaryType "nodebuffer" (default)
return data;
}
else {
// from WebTransport (Uint8Array)
return Buffer.from(data);
}
}
};
const toArrayBuffer = (buffer) => {
const arrayBuffer = new ArrayBuffer(buffer.length);
const view = new Uint8Array(arrayBuffer);
for (let i = 0; i < buffer.length; i++) {
view[i] = buffer[i];
}
return arrayBuffer;
};
exports.default = decodePacket;
import { Packet, RawData } from "./commons.js";
declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export default encodePacket;
export declare function encodePacketToBinary(packet: Packet, callback: (encodedPacket: RawData) => void): void | Promise<void>;
export { encodePacket };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodePacket = exports.encodePacketToBinary = void 0;
const commons_js_1 = require("./commons.js");

@@ -35,2 +36,3 @@ const withNativeBlob = typeof Blob === "function" ||

};
exports.encodePacket = encodePacket;
const encodeBlobAsBase64 = (data, callback) => {

@@ -44,2 +46,32 @@ const fileReader = new FileReader();

};
exports.default = encodePacket;
function toArray(data) {
if (data instanceof Uint8Array) {
return data;
}
else if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
else {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
}
let TEXT_ENCODER;
function encodePacketToBinary(packet, callback) {
if (withNativeBlob && packet.data instanceof Blob) {
return packet.data
.arrayBuffer()
.then(toArray)
.then(callback);
}
else if (withNativeArrayBuffer &&
(packet.data instanceof ArrayBuffer || isView(packet.data))) {
return callback(toArray(packet.data));
}
encodePacket(packet, false, encoded => {
if (!TEXT_ENCODER) {
TEXT_ENCODER = new TextEncoder();
}
callback(TEXT_ENCODER.encode(encoded));
});
}
exports.encodePacketToBinary = encodePacketToBinary;
import { Packet, RawData } from "./commons.js";
declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export default encodePacket;
export declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export declare function encodePacketToBinary(packet: Packet, callback: (encodedPacket: RawData) => void): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodePacketToBinary = exports.encodePacket = void 0;
const commons_js_1 = require("./commons.js");
const encodePacket = ({ type, data }, supportsBinary, callback) => {
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
const buffer = toBuffer(data);
return callback(encodeBuffer(buffer, supportsBinary));
return callback(supportsBinary ? data : "b" + toBuffer(data, true).toString("base64"));
}

@@ -12,4 +12,6 @@ // plain string

};
const toBuffer = data => {
if (Buffer.isBuffer(data)) {
exports.encodePacket = encodePacket;
const toBuffer = (data, forceBufferConversion) => {
if (Buffer.isBuffer(data) ||
(data instanceof Uint8Array && !forceBufferConversion)) {
return data;

@@ -24,6 +26,15 @@ }

};
// only 'message' packets can contain binary, so the type prefix is not needed
const encodeBuffer = (data, supportsBinary) => {
return supportsBinary ? data : "b" + data.toString("base64");
};
exports.default = encodePacket;
let TEXT_ENCODER;
function encodePacketToBinary(packet, callback) {
if (packet.data instanceof ArrayBuffer || ArrayBuffer.isView(packet.data)) {
return callback(toBuffer(packet.data, false));
}
(0, exports.encodePacket)(packet, true, encoded => {
if (!TEXT_ENCODER) {
// lazily created for compatibility with Node.js 10
TEXT_ENCODER = new TextEncoder();
}
callback(TEXT_ENCODER.encode(encoded));
});
}
exports.encodePacketToBinary = encodePacketToBinary;

@@ -1,7 +0,8 @@

import encodePacket from "./encodePacket.js";
import decodePacket from "./decodePacket.js";
import { encodePacket, encodePacketToBinary } from "./encodePacket.js";
import { decodePacket } from "./decodePacket.js";
import { Packet, PacketType, RawData, BinaryType } from "./commons.js";
declare const encodePayload: (packets: Packet[], callback: (encodedPayload: string) => void) => void;
declare const decodePayload: (encodedPayload: string, binaryType?: BinaryType) => Packet[];
export declare function decodePacketFromBinary(data: Uint8Array, isBinary: boolean, binaryType: BinaryType): Packet;
export declare const protocol = 4;
export { encodePacket, encodePayload, decodePacket, decodePayload, Packet, PacketType, RawData, BinaryType };
export { encodePacket, encodePacketToBinary, encodePayload, decodePacket, decodePayload, Packet, PacketType, RawData, BinaryType };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodePayload = exports.decodePacket = exports.encodePayload = exports.encodePacket = exports.protocol = void 0;
exports.decodePayload = exports.decodePacket = exports.encodePayload = exports.encodePacketToBinary = exports.encodePacket = exports.protocol = exports.decodePacketFromBinary = void 0;
const encodePacket_js_1 = require("./encodePacket.js");
exports.encodePacket = encodePacket_js_1.default;
Object.defineProperty(exports, "encodePacket", { enumerable: true, get: function () { return encodePacket_js_1.encodePacket; } });
Object.defineProperty(exports, "encodePacketToBinary", { enumerable: true, get: function () { return encodePacket_js_1.encodePacketToBinary; } });
const decodePacket_js_1 = require("./decodePacket.js");
exports.decodePacket = decodePacket_js_1.default;
Object.defineProperty(exports, "decodePacket", { enumerable: true, get: function () { return decodePacket_js_1.decodePacket; } });
const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text

@@ -16,3 +17,3 @@ const encodePayload = (packets, callback) => {

// force base64 encoding for binary packets
(0, encodePacket_js_1.default)(packet, false, encodedPacket => {
(0, encodePacket_js_1.encodePacket)(packet, false, encodedPacket => {
encodedPackets[i] = encodedPacket;

@@ -30,3 +31,3 @@ if (++count === length) {

for (let i = 0; i < encodedPackets.length; i++) {
const decodedPacket = (0, decodePacket_js_1.default)(encodedPackets[i], binaryType);
const decodedPacket = (0, decodePacket_js_1.decodePacket)(encodedPackets[i], binaryType);
packets.push(decodedPacket);

@@ -40,2 +41,14 @@ if (decodedPacket.type === "error") {

exports.decodePayload = decodePayload;
let TEXT_DECODER;
function decodePacketFromBinary(data, isBinary, binaryType) {
if (!TEXT_DECODER) {
// lazily created for compatibility with old browser platforms
TEXT_DECODER = new TextDecoder();
}
// 48 === "0".charCodeAt(0) (OPEN packet type)
// 54 === "6".charCodeAt(0) (NOOP packet type)
const isPlainBinary = isBinary || data[0] < 48 || data[0] > 54;
return (0, decodePacket_js_1.decodePacket)(isPlainBinary ? data : TEXT_DECODER.decode(data), binaryType);
}
exports.decodePacketFromBinary = decodePacketFromBinary;
exports.protocol = 4;
import { Packet, BinaryType, RawData } from "./commons.js";
declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;
export default decodePacket;
export declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;
import { ERROR_PACKET, PACKET_TYPES_REVERSE } from "./commons.js";
import { decode } from "./contrib/base64-arraybuffer.js";
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
const decodePacket = (encodedPacket, binaryType) => {
export const decodePacket = (encodedPacket, binaryType) => {
if (typeof encodedPacket !== "string") {

@@ -43,8 +43,21 @@ return {

case "blob":
return data instanceof ArrayBuffer ? new Blob([data]) : data;
if (data instanceof Blob) {
// from WebSocket + binaryType "blob"
return data;
}
else {
// from HTTP long-polling or WebTransport
return new Blob([data]);
}
case "arraybuffer":
default:
return data; // assuming the data is already an ArrayBuffer
if (data instanceof ArrayBuffer) {
// from HTTP long-polling (base64) or WebSocket + binaryType "arraybuffer"
return data;
}
else {
// from WebTransport (Uint8Array)
return data.buffer;
}
}
};
export default decodePacket;
import { Packet, BinaryType, RawData } from "./commons.js";
declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;
export default decodePacket;
export declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;
import { ERROR_PACKET, PACKET_TYPES_REVERSE } from "./commons.js";
const decodePacket = (encodedPacket, binaryType) => {
export const decodePacket = (encodedPacket, binaryType) => {
if (typeof encodedPacket !== "string") {

@@ -30,19 +30,27 @@ return {

const mapBinary = (data, binaryType) => {
const isBuffer = Buffer.isBuffer(data);
switch (binaryType) {
case "arraybuffer":
return isBuffer ? toArrayBuffer(data) : data;
if (data instanceof ArrayBuffer) {
// from WebSocket & binaryType "arraybuffer"
return data;
}
else if (Buffer.isBuffer(data)) {
// from HTTP long-polling
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
}
else {
// from WebTransport (Uint8Array)
return data.buffer;
}
case "nodebuffer":
default:
return data; // assuming the data is already a Buffer
if (Buffer.isBuffer(data)) {
// from HTTP long-polling or WebSocket & binaryType "nodebuffer" (default)
return data;
}
else {
// from WebTransport (Uint8Array)
return Buffer.from(data);
}
}
};
const toArrayBuffer = (buffer) => {
const arrayBuffer = new ArrayBuffer(buffer.length);
const view = new Uint8Array(arrayBuffer);
for (let i = 0; i < buffer.length; i++) {
view[i] = buffer[i];
}
return arrayBuffer;
};
export default decodePacket;
import { Packet, RawData } from "./commons.js";
declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export default encodePacket;
export declare function encodePacketToBinary(packet: Packet, callback: (encodedPacket: RawData) => void): void | Promise<void>;
export { encodePacket };

@@ -41,2 +41,32 @@ import { PACKET_TYPES } from "./commons.js";

};
export default encodePacket;
function toArray(data) {
if (data instanceof Uint8Array) {
return data;
}
else if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
else {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
}
let TEXT_ENCODER;
export function encodePacketToBinary(packet, callback) {
if (withNativeBlob && packet.data instanceof Blob) {
return packet.data
.arrayBuffer()
.then(toArray)
.then(callback);
}
else if (withNativeArrayBuffer &&
(packet.data instanceof ArrayBuffer || isView(packet.data))) {
return callback(toArray(packet.data));
}
encodePacket(packet, false, encoded => {
if (!TEXT_ENCODER) {
TEXT_ENCODER = new TextEncoder();
}
callback(TEXT_ENCODER.encode(encoded));
});
}
export { encodePacket };
import { Packet, RawData } from "./commons.js";
declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export default encodePacket;
export declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export declare function encodePacketToBinary(packet: Packet, callback: (encodedPacket: RawData) => void): void;
import { PACKET_TYPES } from "./commons.js";
const encodePacket = ({ type, data }, supportsBinary, callback) => {
export const encodePacket = ({ type, data }, supportsBinary, callback) => {
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
const buffer = toBuffer(data);
return callback(encodeBuffer(buffer, supportsBinary));
return callback(supportsBinary ? data : "b" + toBuffer(data, true).toString("base64"));
}

@@ -10,4 +9,5 @@ // plain string

};
const toBuffer = data => {
if (Buffer.isBuffer(data)) {
const toBuffer = (data, forceBufferConversion) => {
if (Buffer.isBuffer(data) ||
(data instanceof Uint8Array && !forceBufferConversion)) {
return data;

@@ -22,6 +22,14 @@ }

};
// only 'message' packets can contain binary, so the type prefix is not needed
const encodeBuffer = (data, supportsBinary) => {
return supportsBinary ? data : "b" + data.toString("base64");
};
export default encodePacket;
let TEXT_ENCODER;
export function encodePacketToBinary(packet, callback) {
if (packet.data instanceof ArrayBuffer || ArrayBuffer.isView(packet.data)) {
return callback(toBuffer(packet.data, false));
}
encodePacket(packet, true, encoded => {
if (!TEXT_ENCODER) {
// lazily created for compatibility with Node.js 10
TEXT_ENCODER = new TextEncoder();
}
callback(TEXT_ENCODER.encode(encoded));
});
}

@@ -1,7 +0,8 @@

import encodePacket from "./encodePacket.js";
import decodePacket from "./decodePacket.js";
import { encodePacket, encodePacketToBinary } from "./encodePacket.js";
import { decodePacket } from "./decodePacket.js";
import { Packet, PacketType, RawData, BinaryType } from "./commons.js";
declare const encodePayload: (packets: Packet[], callback: (encodedPayload: string) => void) => void;
declare const decodePayload: (encodedPayload: string, binaryType?: BinaryType) => Packet[];
export declare function decodePacketFromBinary(data: Uint8Array, isBinary: boolean, binaryType: BinaryType): Packet;
export declare const protocol = 4;
export { encodePacket, encodePayload, decodePacket, decodePayload, Packet, PacketType, RawData, BinaryType };
export { encodePacket, encodePacketToBinary, encodePayload, decodePacket, decodePayload, Packet, PacketType, RawData, BinaryType };

@@ -1,3 +0,3 @@

import encodePacket from "./encodePacket.js";
import decodePacket from "./decodePacket.js";
import { encodePacket, encodePacketToBinary } from "./encodePacket.js";
import { decodePacket } from "./decodePacket.js";
const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text

@@ -31,3 +31,14 @@ const encodePayload = (packets, callback) => {

};
let TEXT_DECODER;
export function decodePacketFromBinary(data, isBinary, binaryType) {
if (!TEXT_DECODER) {
// lazily created for compatibility with old browser platforms
TEXT_DECODER = new TextDecoder();
}
// 48 === "0".charCodeAt(0) (OPEN packet type)
// 54 === "6".charCodeAt(0) (NOOP packet type)
const isPlainBinary = isBinary || data[0] < 48 || data[0] > 54;
return decodePacket(isPlainBinary ? data : TEXT_DECODER.decode(data), binaryType);
}
export const protocol = 4;
export { encodePacket, encodePayload, decodePacket, decodePayload };
export { encodePacket, encodePacketToBinary, encodePayload, decodePacket, decodePayload };

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "5.0.7",
"version": "5.1.0",
"main": "./build/cjs/index.js",

@@ -8,0 +8,0 @@ "module": "./build/esm/index.js",

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