mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-26 22:15:01 +02:00
16 lines
477 B
TypeScript
16 lines
477 B
TypeScript
import { gzipSync, gunzipSync } from "zlib";
|
|
|
|
/**
|
|
* Gzip a string and return it as base64 so it can be stored in a TEXT column.
|
|
*/
|
|
export function compressText(value: string): string {
|
|
return gzipSync(Buffer.from(value, "utf8")).toString("base64");
|
|
}
|
|
|
|
/**
|
|
* Reverse of compressText - base64-decode and gunzip back to the original string.
|
|
*/
|
|
export function decompressText(value: string): string {
|
|
return gunzipSync(Buffer.from(value, "base64")).toString("utf8");
|
|
}
|