{"action":"closed","issue":{"url":"https://api.github.com/repos/socketio/engine.io-parser/issues/60","repository_url":"https://api.github.com/repos/socketio/engine.io-parser","labels_url":"https://api.github.com/repos/socketio/engine.io-parser/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/socketio/engine.io-parser/issues/60/comments","events_url":"https://api.github.com/repos/socketio/engine.io-parser/issues/60/events","html_url":"https://github.com/socketio/engine.io-parser/issues/60","id":165253539,"number":60,"title":"Badly handle ArrayBuffer type","user":{"login":"ghostoy","id":471928,"avatar_url":"https://avatars.githubusercontent.com/u/471928?v=3","gravatar_id":"","url":"https://api.github.com/users/ghostoy","html_url":"https://github.com/ghostoy","followers_url":"https://api.github.com/users/ghostoy/followers","following_url":"https://api.github.com/users/ghostoy/following{/other_user}","gists_url":"https://api.github.com/users/ghostoy/gists{/gist_id}","starred_url":"https://api.github.com/users/ghostoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghostoy/subscriptions","organizations_url":"https://api.github.com/users/ghostoy/orgs","repos_url":"https://api.github.com/users/ghostoy/repos","events_url":"https://api.github.com/users/ghostoy/events{/privacy}","received_events_url":"https://api.github.com/users/ghostoy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-07-13T07:20:00Z","updated_at":"2016-10-20T12:17:32Z","closed_at":"2016-10-20T12:17:32Z","body":"This issue is originated from nwjs/nw.js#5034. When using Socket.io in latest NW.js, binary data cannot be handles properly.\r\n\r\nThe root cause is that engine.io-parser doesn't handle `ArrayBuffer` properly. See [lib/index.js:L148-L157](https://github.com/socketio/engine.io-parser/blob/master/lib/index.js#L148-L157).\r\n\r\n```javascript\r\n  if (binaryType === 'arraybuffer') { // <-- [1]\r\n    var type = data[0]; // <-- [2]\r\n    var intArray = new Uint8Array(data.length - 1);\r\n    for (var i = 1; i < data.length; i++) {\r\n      intArray[i - 1] = data[i];\r\n    }\r\n    return { type: packetslist[type], data: intArray.buffer };\r\n  }\r\n  var type = data[0]; // <-- [3] \r\n  return { type: packetslist[type], data: data.slice(1) };\r\n```\r\n\r\n1. In Node.js or NW.js, `binaryType` is always `null`. I assume it's a bug as well.\r\n2. `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.\r\n3. 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`."}}
{"actor":{"display_login":"darrachequesne"}}