Skip to content

Instantly share code, notes, and snippets.

@heinrich-ulbricht
Created June 11, 2021 13:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heinrich-ulbricht/683ea2ac8ac0e7bc607e4f4a57534937 to your computer and use it in GitHub Desktop.
Save heinrich-ulbricht/683ea2ac8ac0e7bc607e4f4a57534937 to your computer and use it in GitHub Desktop.
JavaScript: Compressing a string to send via query parameter
// 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