Add comments
This commit is contained in:
parent
e76d91a484
commit
38a2bf14c8
1 changed files with 17 additions and 0 deletions
|
@ -16,6 +16,10 @@ let rootURLSize = 0;
|
|||
let statusEl = null;
|
||||
let codeEl = null;
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves when the page DOM has been loaded.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
function waitForLoad() {
|
||||
return new Promise(resolve => {
|
||||
// If already loaded, fire immediately
|
||||
|
@ -28,6 +32,10 @@ function waitForLoad() {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the max length of the hash that we can use to avoid overlong URLs.
|
||||
* @returns {number}
|
||||
*/
|
||||
function maxHashLength() {
|
||||
if (rootURLSize === 0) {
|
||||
const rootURL = new URL(window.location.href);
|
||||
|
@ -38,6 +46,10 @@ function maxHashLength() {
|
|||
return MAX_URL - rootURLSize - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the given data in a synchronous way (all at once) and update the status.
|
||||
* @param {Uint8Array} data
|
||||
*/
|
||||
async function syncCompress(data) {
|
||||
const compressed = compress(ENCODER.encode(data), { quality: QUALITY });
|
||||
const encoded = BASE66CODEC.encode(compressed);
|
||||
|
@ -51,6 +63,11 @@ async function syncCompress(data) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress the given data in a streaming way, with pauses between every chunk, to avoid
|
||||
* the user being zip bombed with a short hash that generates gigabytes of output.
|
||||
* @param {Uint8Array} data
|
||||
*/
|
||||
async function streamDecompress(data) {
|
||||
statusEl.textContent = "Initializing decompress...";
|
||||
|
||||
|
|
Loading…
Reference in a new issue