Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable raw bytes data output for edge cases #191

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qr-scanner-worker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion qr-scanner-worker.min.js.map

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions qr-scanner.legacy.min.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions qr-scanner.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion qr-scanner.min.js.map

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions qr-scanner.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion qr-scanner.umd.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/qr-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ class QrScanner {
resolve({
data: event.data.data,
cornerPoints: QrScanner._convertPoints(event.data.cornerPoints, scanRegion),
bytes: event.data.bytes
});
} else {
reject(QrScanner.NO_QR_CODE_FOUND);
Expand Down Expand Up @@ -559,6 +560,7 @@ class QrScanner {
return {
data: scanResult.rawValue,
cornerPoints: QrScanner._convertPoints(scanResult.cornerPoints, scanRegion),
bytes: scanResult.rawValue.split('').map(c => c.charCodeAt(0)),
};
} catch (e) {
const errorMessage = (e as Error).message || e as string;
Expand Down Expand Up @@ -1073,6 +1075,7 @@ declare namespace QrScanner {
data: string;
// In clockwise order, starting at top left, but this might not be guaranteed in the future.
cornerPoints: QrScanner.Point[];
bytes: Number[];
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ function decode(data: { data: Uint8ClampedArray, width: number, height: number }
id: requestId,
type: 'qrResult',
data: result.data,
// jsQR doesn't return anything in data if it is binary, so we sometime
// need to use the raw binary value (also useful for other languages like Mandarin)
bytes: result.binaryData,
// equivalent to cornerPoints of native BarcodeDetector
cornerPoints: [
result.location.topLeftCorner,
Expand Down
1 change: 1 addition & 0 deletions types/qr-scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ declare namespace QrScanner {
interface ScanResult {
data: string;
cornerPoints: QrScanner.Point[];
bytes: Number[];
}
}
declare class BarcodeDetector {
Expand Down