forked from sacrosanctic/svelte-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
19 lines (18 loc) · 657 Bytes
/
utils.js
File metadata and controls
19 lines (18 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// https://github.com/sveltejs/svelte.dev//blob/main/apps/svelte.dev/src/routes/(authed)/playground/%5Bid%5D/gzip.js#L1-L17
/** @param {string} input */
export async function compress_and_encode_text(input) {
const reader = new Blob([input]).stream().pipeThrough(new CompressionStream('gzip')).getReader()
let buffer = ''
for (;;) {
const { done, value } = await reader.read()
if (done) {
reader.releaseLock()
return btoa(buffer).replaceAll('+', '-').replaceAll('/', '_')
} else {
for (let i = 0; i < value.length; i++) {
// decoding as utf-8 will make btoa reject the string
buffer += String.fromCharCode(value[i])
}
}
}
}