vue-qrcode-reader icon indicating copy to clipboard operation
vue-qrcode-reader copied to clipboard

feat: give the binaryData of the QR code.

Open shimadev opened this issue 3 years ago • 3 comments

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.

shimadev avatar Sep 30 '20 12:09 shimadev

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

gruhn avatar Oct 01 '20 09:10 gruhn

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

shimadev avatar Oct 09 '20 08:10 shimadev

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.

gruhn avatar Oct 09 '20 17:10 gruhn

This pull request has been marked as stale. If there is no further activity it will be closed.

github-actions[bot] avatar Aug 04 '23 00:08 github-actions[bot]