Skip to content

Badly handle ArrayBuffer type #60

@ghostoy

Description

@ghostoy

This issue is originated from nwjs/nw.js#5034. When using Socket.io in latest NW.js, binary data cannot be handles properly.

The root cause is that engine.io-parser doesn't handle ArrayBuffer properly. See lib/index.js:L148-L157.

  if (binaryType === 'arraybuffer') { // <-- [1]
    var type = data[0]; // <-- [2]
    var intArray = new Uint8Array(data.length - 1);
    for (var i = 1; i < data.length; i++) {
      intArray[i - 1] = data[i];
    }
    return { type: packetslist[type], data: intArray.buffer };
  }
  var type = data[0]; // <-- [3] 
  return { type: packetslist[type], data: data.slice(1) };
  1. In Node.js or NW.js, binaryType is always null. I assume it's a bug as well.
  2. ArrayBuffer cannot be directly read using array styled syntax data[0]. One should construct a TypedArray form the buffer, such as Uint8Array, and read the data inside.
  3. I guess here it assumes data could only be a Node Buffer. However, in NW.js data can be of type ArrayBuffer from browser builtin WebSocket.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions