source: trip-planner-front/node_modules/engine.io-parser/build/cjs/encodePacket.browser.js@ bdd6491

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

primeNG components

  • Property mode set to 100644
File size: 1.5 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const commons_js_1 = require("./commons.js");
4const withNativeBlob = typeof Blob === "function" ||
5 (typeof Blob !== "undefined" &&
6 Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
7const withNativeArrayBuffer = typeof ArrayBuffer === "function";
8// ArrayBuffer.isView method is not defined in IE10
9const isView = obj => {
10 return typeof ArrayBuffer.isView === "function"
11 ? ArrayBuffer.isView(obj)
12 : obj && obj.buffer instanceof ArrayBuffer;
13};
14const encodePacket = ({ type, data }, supportsBinary, callback) => {
15 if (withNativeBlob && data instanceof Blob) {
16 if (supportsBinary) {
17 return callback(data);
18 }
19 else {
20 return encodeBlobAsBase64(data, callback);
21 }
22 }
23 else if (withNativeArrayBuffer &&
24 (data instanceof ArrayBuffer || isView(data))) {
25 if (supportsBinary) {
26 return callback(data);
27 }
28 else {
29 return encodeBlobAsBase64(new Blob([data]), callback);
30 }
31 }
32 // plain string
33 return callback(commons_js_1.PACKET_TYPES[type] + (data || ""));
34};
35const encodeBlobAsBase64 = (data, callback) => {
36 const fileReader = new FileReader();
37 fileReader.onload = function () {
38 const content = fileReader.result.split(",")[1];
39 callback("b" + content);
40 };
41 return fileReader.readAsDataURL(data);
42};
43exports.default = encodePacket;
Note: See TracBrowser for help on using the repository browser.