Created
June 11, 2021 13:38
-
-
Save heinrich-ulbricht/683ea2ac8ac0e7bc607e4f4a57534937 to your computer and use it in GitHub Desktop.
JavaScript: Compressing a string to send via query parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pako finally worked (browser, Teams desktop client, Teams Android client); I tried/checked a lot of libraries but they either produced wrong results, did not compress good or were old or without good docs: shorter, shoco, lzma-js, lzutf8 (did not work in Teams Android client), lz-string | |
const pako = require('pako'); | |
const {Base64} = require('js-base64'); | |
let stringToCompress = 'test'; | |
let compressedStringBytes = pako.deflate(stringToCompress); | |
let compressedStringBytesBase64 = Base64.fromUint8Array(compressedStringBytes, true); | |
// send via query parameter | |
// ----------------------------- | |
compressedStringBytesBase64_Received = compressedStringBytesBase64; | |
// ----------------------------- | |
let compressedStringBytes_Received = Base64.toUint8Array(compressedStringBytesBase64_Received); | |
let stringToCompress_Received = pako.inflate(compressedStringBytes_Received, {to: "string"}); | |
console.log(stringToCompress_Received); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment