piderman314 / bardecoder

Detect and decode QR Codes, written in 100% Rust.
MIT License
268 stars 34 forks source link

Way to read binary encoding as raw binary? #52

Closed KyleMaas closed 1 year ago

KyleMaas commented 1 year ago

Is there a way to skip the encoding autodetection in the binary mode and just read the raw byte data?

https://github.com/piderman314/bardecoder/blob/e1fcff7f4975c8f9cc430b61b0a0ac29a4b1dd78/src/decode/qr/data.rs#L167-L187

piderman314 commented 1 year ago

I don't think this is very useful. QR codes are meant to store text and thus even the "binary" mode is intended to store ISO8859-1 or UTF-8. If you really need to have raw binary data I would suggest using something like base64 to convert it into characters.

KyleMaas commented 1 year ago

In my case, I'm trying to use QR codes as a data storage/transmission medium, not for direct reading. Direct binary would be far more data dense than the way I'm currently having to do it, which is base45-encoded. But I can understand your concern with adding a seldom-useful feature.

piderman314 commented 1 year ago

It's not even that it would be seldom-used, it's incompatible with QRs and the rest of the library. The other modes aren't even binary, they are packed decimal or even just a proprietary character encoding. For those, there is no other sensible output type except String. I just can't see it working type-wise to (also) return the binary without heavily compromising the output type or a lot of code duplication.

KyleMaas commented 1 year ago

Okay. Thank you!

jerabaul29 commented 1 year ago

A note: the need for storing binary data in qr codes is discussed on quite many places on the internet, and several packages support it. See for example the discussion at:

https://stackoverflow.com/questions/60506222/encode-decode-binary-data-in-a-qr-code-using-qrencode-and-zbarimg-in-bash

The maintainers of zbarimg ended up agreeing that supporting binary data is useful, and adding it to zbarimg.

I think that could be a nice feature to have on the roadmap to add in the future :) .