mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
25 lines
554 B
JavaScript
25 lines
554 B
JavaScript
import { decode, encode } from "base64-arraybuffer";
|
|
import { compressSync, strToU8, strFromU8 } from "fflate";
|
|
|
|
/**
|
|
*
|
|
* @param {string} data
|
|
* @returns {string | null} An object containing compressed data
|
|
*/
|
|
export const compress = (data) => {
|
|
try {
|
|
return encode(compressSync(strToU8(data)).buffer);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @param {string} compressed
|
|
* @returns {string} decompressed string
|
|
*/
|
|
export const decompress = (compressed) => {
|
|
return strFromU8(decompressSync(new Uint8Array(decode(compressed))));
|
|
};
|