Skip to content

Commit

Permalink
Added tests for exif-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
serratus committed Aug 14, 2016
1 parent 6d5fd9d commit ce4d4a9
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .eslintrc
Expand Up @@ -24,7 +24,12 @@
"objectLiteralComputedProperties": true
},
"globals": {
"ENV": true
"ENV": true,
"beforeEach": true,
"describe": true,
"it": true,
"expect": true,
"sinon": true
},
"rules": {
"no-unused-expressions": 1,
Expand Down
24 changes: 19 additions & 5 deletions dist/quagga.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/quagga.min.js

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions src/input/exif_helper.js
Expand Up @@ -12,6 +12,19 @@ export function findTagsInObjectURL(src, tags = AvailableTags) {
return Promise.resolve(null);
}

export function base64ToArrayBuffer(dataUrl) {
const base64 = dataUrl.replace(/^data\:([^\;]+)\;base64,/gmi, ''),
binary = atob(base64),
len = binary.length,
buffer = new ArrayBuffer(len),
view = new Uint8Array(buffer);

for (let i = 0; i < len; i++) {
view[i] = binary.charCodeAt(i);
}
return buffer;
}

function readToBuffer(blob) {
return new Promise(resolve => {
const fileReader = new FileReader();
Expand All @@ -23,20 +36,21 @@ function readToBuffer(blob) {
}

function objectURLToBlob(url) {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
const http = new XMLHttpRequest();
http.open("GET", url, true);
http.responseType = "blob";
http.onload = function() {
if (this.status === 200 || this.status === 0) {
http.onreadystatechange = function () {
if (http.readyState === XMLHttpRequest.DONE && (http.status === 200 || http.status === 0)) {
resolve(this.response);
}
};
http.onerror = reject;
http.send();
});
}

function findTagsInBuffer(file, selectedTags = AvailableTags) {
export function findTagsInBuffer(file, selectedTags = AvailableTags) {
const dataView = new DataView(file),
length = file.byteLength,
exifTags = selectedTags.reduce((result, selectedTag) => {
Expand Down
59 changes: 59 additions & 0 deletions test/spec/exif_helper.spec.js

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

0 comments on commit ce4d4a9

Please sign in to comment.