MCPcopy
hub / github.com/socketio/socket.io / encodePacket

Function encodePacket

packages/engine.io-parser/lib/encodePacket.browser.ts:16–39  ·  view source on GitHub ↗
(
  { type, data }: Packet,
  supportsBinary: boolean,
  callback: (encodedPacket: RawData) => void,
)

Source from the content-addressed store, hash-verified

14};
15
16const encodePacket = (
17 { type, data }: Packet,
18 supportsBinary: boolean,
19 callback: (encodedPacket: RawData) => void,
20) => {
21 if (withNativeBlob && data instanceof Blob) {
22 if (supportsBinary) {
23 return callback(data);
24 } else {
25 return encodeBlobAsBase64(data, callback);
26 }
27 } else if (
28 withNativeArrayBuffer &&
29 (data instanceof ArrayBuffer || isView(data))
30 ) {
31 if (supportsBinary) {
32 return callback(data);
33 } else {
34 return encodeBlobAsBase64(new Blob([data]), callback);
35 }
36 }
37 // plain string
38 return callback(PACKET_TYPES[type] + (data || ""));
39};
40
41const encodeBlobAsBase64 = (
42 data: Blob,

Callers 1

encodePacketToBinaryFunction · 0.70

Calls 3

encodeBlobAsBase64Function · 0.70
isViewFunction · 0.70
callbackFunction · 0.50

Tested by

no test coverage detected