aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils
diff options
context:
space:
mode:
Diffstat (limited to 'webAO/utils')
-rw-r--r--webAO/utils/calculateApngLength.js28
-rw-r--r--webAO/utils/fileExists.js37
-rw-r--r--webAO/utils/getAnimLength.js2
3 files changed, 31 insertions, 36 deletions
diff --git a/webAO/utils/calculateApngLength.js b/webAO/utils/calculateApngLength.js
index 86c2073..932f581 100644
--- a/webAO/utils/calculateApngLength.js
+++ b/webAO/utils/calculateApngLength.js
@@ -1,25 +1,25 @@
- /**
+/**
* Adds up the chunk delays to find out how long a APNG is
* @param {data} apngFile the APNG data
*/
const calculateApngLength = (apngFile) => {
const d = new Uint8Array(apngFile);
- // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk
- let duration = 0;
- for (var i = 0; i < d.length; i++) {
- // Find fcTL header (66 63 54 4C)
- if (d[i] === 0x66
+ // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk
+ let duration = 0;
+ for (let i = 0; i < d.length; i++) {
+ // Find fcTL header (66 63 54 4C)
+ if (d[i] === 0x66
&& d[i + 1] === 0x63
&& d[i + 2] === 0x54
&& d[i + 3] === 0x4C) {
- // numerator and denominator
- let delay = ((d[i + 21] / d[i + 23]) * 1000)
+ // numerator and denominator
+ const delay = ((d[i + 21] / d[i + 23]) * 1000);
- // minimum is 100ms
- duration += delay < 100 ? 100 : delay;
- }
- }
- console.debug(duration);
- return duration * 10;
+ // minimum is 100ms
+ duration += delay < 100 ? 100 : delay;
+ }
+ }
+ console.debug(duration);
+ return duration * 10;
};
export default calculateApngLength;
diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js
index 3065112..13958e0 100644
--- a/webAO/utils/fileExists.js
+++ b/webAO/utils/fileExists.js
@@ -1,23 +1,18 @@
-
-const fileExists = async (url) => {
- return new Promise((resolve, reject) => {
- const xhr = new XMLHttpRequest();
- xhr.open('HEAD', url);
- xhr.onload = function (e) {
- if (xhr.readyState === 4) {
- if (xhr.status === 200) {
- resolve(true)
- } else {
- reject(false)
- }
+const fileExists = async (url) => new Promise((resolve, reject) => {
+ const xhr = new XMLHttpRequest();
+ xhr.open('HEAD', url);
+ xhr.onload = function (e) {
+ if (xhr.readyState === 4) {
+ if (xhr.status === 200) {
+ resolve(true);
+ } else {
+ reject(false);
}
- };
- xhr.onerror = function (e) {
- resolve(false)
- };
- xhr.send(null);
- })
-
-
-};
+ }
+ };
+ xhr.onerror = function (e) {
+ resolve(false);
+ };
+ xhr.send(null);
+});
export default fileExists;
diff --git a/webAO/utils/getAnimLength.js b/webAO/utils/getAnimLength.js
index 1441548..aa303cf 100644
--- a/webAO/utils/getAnimLength.js
+++ b/webAO/utils/getAnimLength.js
@@ -1,6 +1,6 @@
import calculatorHandler from './calculatorHandler';
import fileExists from './fileExists.js';
-import {requestBuffer} from '../services/request.js';
+import { requestBuffer } from '../services/request.js';
/**
* Gets animation length. If the animation cannot be found, it will
* silently fail and return 0 instead.