diff options
author | Minteck <contact@minteck.org> | 2022-06-14 12:35:20 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-06-14 12:35:20 +0200 |
commit | ff41be60a71899b872dea431c846bcc3ca1e8dc2 (patch) | |
tree | 1b721a8d7c7074a8a77b8874857f9182b4b700c5 | |
parent | c246f73616c0c3e99a35e52ee6f6a55116b91c09 (diff) | |
download | elac-ff41be60a71899b872dea431c846bcc3ca1e8dc2.tar.gz elac-ff41be60a71899b872dea431c846bcc3ca1e8dc2.tar.bz2 elac-ff41be60a71899b872dea431c846bcc3ca1e8dc2.zip |
Browser lib 2
-rw-r--r-- | browser/src/elac.js | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/browser/src/elac.js b/browser/src/elac.js index fddab1a..ffdba44 100644 --- a/browser/src/elac.js +++ b/browser/src/elac.js @@ -1,4 +1,4 @@ -class EQMCData extends Object { +class ELACData extends Object { constructor(obj) { super(); @@ -8,7 +8,7 @@ class EQMCData extends Object { } } -class EQMCAudioStream extends Object { +class ELACAudioStream extends Object { constructor(obj) { super(); @@ -18,14 +18,14 @@ class EQMCAudioStream extends Object { } } -class EQMCError extends Error { +class ELACError extends Error { constructor(props) { super(props); - this.name = "EQMCError"; + this.name = "ELACError"; } } -window.EQMC = { +window.ELAC = { _base64ToArrayBuffer: (base64) => { var binary_string = window.atob(base64); var len = binary_string.length; @@ -36,44 +36,44 @@ window.EQMC = { return bytes.buffer; }, - isEQMCData: async (data) => { - return data instanceof EQMCData && data["_eqmc"]; + isELACData: async (data) => { + return data instanceof ELACData && data["_eqmc"]; }, - isEQMCAudioStream: async (data) => { - return data instanceof EQMCAudioStream && data["data"]; + isELACAudioStream: async (data) => { + return data instanceof ELACAudioStream && data["data"]; }, create: async (file) => { try { - return new EQMCData(JSON.parse(new TextDecoder("utf-8").decode(pako.inflate(new Uint8Array((await (await (await window.fetch(file)).blob()).arrayBuffer())))))); + return new ELACData(JSON.parse(new TextDecoder("utf-8").decode(pako.inflate(new Uint8Array((await (await (await window.fetch(file)).blob()).arrayBuffer())))))); } catch (e) { console.error(e); - throw new EQMCError("Failed to construct EQMCData object"); + throw new ELACError("Failed to construct ELACData object"); } }, decodeFile: async (data, file) => { - if (!await EQMC.isEQMCData(data)) throw new EQMCError("Invalid input, expected EQMCData"); + if (!await ELAC.isELACData(data)) throw new ELACError("Invalid input, expected ELACData"); if (data.files.length - 1 >= file) { let s = data.files[file]; - s["data"] = new Blob([pako.inflate(EQMC._base64ToArrayBuffer(s.data))]); - return new EQMCAudioStream(s); + s["data"] = new Blob([pako.inflate(ELAC._base64ToArrayBuffer(s.data))]); + return new ELACAudioStream(s); } else { - throw new EQMCError("File index is out of range"); + throw new ELACError("File index is out of range"); } }, toAudio: async (data) => { - if (!await EQMC.isEQMCAudioStream(data)) throw new EQMCError("Invalid input, expected EQMCAudioStream"); + if (!await ELAC.isELACAudioStream(data)) throw new ELACError("Invalid input, expected ELACAudioStream"); return new Audio(window.URL.createObjectURL(data.data)); }, quickAudio: async (url, id) => { - let eqmc = await EQMC.create(url); - let file = await EQMC.decodeFile(eqmc, id); - return await EQMC.toAudio(file); + let elac = await ELAC.create(url); + let file = await ELAC.decodeFile(elac, id); + return await elac.toAudio(file); } }
\ No newline at end of file |