use messagepack to make it even smaller!!!!

This commit is contained in:
grngxd 2025-07-31 21:04:01 +01:00
parent a5457c6cc6
commit b6e24c517b
4 changed files with 28 additions and 10 deletions

View file

@ -1,11 +1,13 @@
import m from "msgpack-lite";
// i actually love this
export const b64encode = (obj: object): string => {
return Buffer.from(JSON.stringify(obj)).toString("base64url");
return Buffer.from(m.encode(obj)).toString("base64url");
}
export const b64decode = <T>(str: string): T => {
try {
return JSON.parse(Buffer.from(str, "base64url").toString());
return m.decode(Buffer.from(str, "base64url"));
} catch {
throw new Error("invalid base64-encoded object string: " + str);
}