diff options
author | Minteck <contact@minteck.org> | 2022-06-14 14:37:15 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-06-14 14:37:15 +0200 |
commit | 298fe9906d363a02408a3f3443ca63950e9a4778 (patch) | |
tree | 4a34304a1afc34ff764c7d998dcb42dd4ec4d546 | |
parent | 8a88dea702b735db7ff659e4c9d96a1ea00839bd (diff) | |
download | elac-298fe9906d363a02408a3f3443ca63950e9a4778.tar.gz elac-298fe9906d363a02408a3f3443ca63950e9a4778.tar.bz2 elac-298fe9906d363a02408a3f3443ca63950e9a4778.zip |
More features for the browser
-rw-r--r-- | browser/elac.js | 44 | ||||
-rw-r--r-- | browser/src/elac.js | 6 |
2 files changed, 31 insertions, 19 deletions
diff --git a/browser/elac.js b/browser/elac.js index a0ddbd5..5198bba 100644 --- a/browser/elac.js +++ b/browser/elac.js @@ -6727,7 +6727,7 @@ }))); -class EQMCData extends Object { +class ELACData extends Object { constructor(obj) { super(); @@ -6737,7 +6737,7 @@ class EQMCData extends Object { } } -class EQMCAudioStream extends Object { +class ELACAudioStream extends Object { constructor(obj) { super(); @@ -6747,14 +6747,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; @@ -6765,44 +6765,50 @@ 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); + }, + + quickBlob: async (url, id) => { + let elac = await ELAC.create(url); + let file = await ELAC.decodeFile(elac, id); + return window.URL.createObjectURL(file.data); } }
\ No newline at end of file diff --git a/browser/src/elac.js b/browser/src/elac.js index ffdba44..61b8878 100644 --- a/browser/src/elac.js +++ b/browser/src/elac.js @@ -75,5 +75,11 @@ window.ELAC = { let elac = await ELAC.create(url); let file = await ELAC.decodeFile(elac, id); return await elac.toAudio(file); + }, + + quickBlob: async (url, id) => { + let elac = await ELAC.create(url); + let file = await ELAC.decodeFile(elac, id); + return window.URL.createObjectURL(file.data); } }
\ No newline at end of file |