I work with Parallel.js and Q.js to implement Multithreading in my application. Since I can only transfer serializable objects to Parallel.js, and I need to pass ArrayBuffer, I converted ArrayBuffer to Uint8Array as a JSON object with this JSON.stringify(new Uint8Array(bytes)), and then to Parallel.js I convert the JSON object to an object, then try Uint8Array and then to my buffer like this
var object = JSON.parse(data[0]);
var bytes = new Uint8Array(Object.keys(object).map(function(k) { return object[k]}));
var buffer = bytes.buffer;
this usually works because Uint8Array has a prototype called buffer, but the buffer is always undefined. The object and bytes are correct, when I look at the prototype of bufferbytes, I see this message: [Exception: TypeError: Method Uint8Array.buffer called on incompatible receiver #<Uint8Array>]And I really don't know how I should fix it.
Does anyone know of a fix?
source
share