source: trip-planner-front/node_modules/engine.io-parser/build/cjs/decodePacket.browser.js@ 8d391a1

Last change on this file since 8d391a1 was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 1.6 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const commons_js_1 = require("./commons.js");
4const base64_arraybuffer_1 = require("base64-arraybuffer");
5const withNativeArrayBuffer = typeof ArrayBuffer === "function";
6const decodePacket = (encodedPacket, binaryType) => {
7 if (typeof encodedPacket !== "string") {
8 return {
9 type: "message",
10 data: mapBinary(encodedPacket, binaryType)
11 };
12 }
13 const type = encodedPacket.charAt(0);
14 if (type === "b") {
15 return {
16 type: "message",
17 data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
18 };
19 }
20 const packetType = commons_js_1.PACKET_TYPES_REVERSE[type];
21 if (!packetType) {
22 return commons_js_1.ERROR_PACKET;
23 }
24 return encodedPacket.length > 1
25 ? {
26 type: commons_js_1.PACKET_TYPES_REVERSE[type],
27 data: encodedPacket.substring(1)
28 }
29 : {
30 type: commons_js_1.PACKET_TYPES_REVERSE[type]
31 };
32};
33const decodeBase64Packet = (data, binaryType) => {
34 if (withNativeArrayBuffer) {
35 const decoded = (0, base64_arraybuffer_1.decode)(data);
36 return mapBinary(decoded, binaryType);
37 }
38 else {
39 return { base64: true, data }; // fallback for old browsers
40 }
41};
42const mapBinary = (data, binaryType) => {
43 switch (binaryType) {
44 case "blob":
45 return data instanceof ArrayBuffer ? new Blob([data]) : data;
46 case "arraybuffer":
47 default:
48 return data; // assuming the data is already an ArrayBuffer
49 }
50};
51exports.default = decodePacket;
Note: See TracBrowser for help on using the repository browser.