vue-qrcode-reader
vue-qrcode-reader copied to clipboard
feat: give the binaryData of the QR code.
The jsQR
library return binary data, when QR code is able to decoded.
I added binaryData
to the payload passed by the worker.
In my use case, I store the compressed binary data in a QR code, so I need the raw data.
Thanks! Also for updating the documentation already.
Can you make a small change to the postMessage
part though? I think it should look like this:
self.postMessage(message, [imageData.data.buffer, binaryData.buffer]);
Passing data between worker and main thread can be expense because the data is copied. The statement above basically instructs the worker to give up ownership of the data and transfer instead of copying it.
Checkout the section Passing data by transferring ownership (transferable objects) at https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
Thanks for reply!
I read the MDN doc and understood about transferring ownership.
But the binaryData
is not a transferable objects, it is Array of numbers.
https://github.com/cozmo/jsQR/blob/master/dist/index.d.ts#L4
I think the TypeScript type number[]
is transpiled to a Uint8ClampedArray
as state here:
https://github.com/cozmo/jsQR#return-value
Uint8ClampedArray in turn has an instance property called buffer
which is an ArrayBuffer and that's transferable.
This pull request has been marked as stale. If there is no further activity it will be closed.