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

Function mapBinary

packages/engine.io-parser/lib/decodePacket.ts:40–66  ·  view source on GitHub ↗
(data: RawData, binaryType?: BinaryType)

Source from the content-addressed store, hash-verified

38};
39
40const mapBinary = (data: RawData, binaryType?: BinaryType) => {
41 switch (binaryType) {
42 case "arraybuffer":
43 if (data instanceof ArrayBuffer) {
44 // from WebSocket & binaryType "arraybuffer"
45 return data;
46 } else if (Buffer.isBuffer(data)) {
47 // from HTTP long-polling
48 return data.buffer.slice(
49 data.byteOffset,
50 data.byteOffset + data.byteLength,
51 );
52 } else {
53 // from WebTransport (Uint8Array)
54 return data.slice().buffer;
55 }
56 case "nodebuffer":
57 default:
58 if (Buffer.isBuffer(data)) {
59 // from HTTP long-polling or WebSocket & binaryType "nodebuffer" (default)
60 return data;
61 } else {
62 // from WebTransport (Uint8Array)
63 return Buffer.from(data);
64 }
65 }
66};

Callers 1

decodePacketFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected