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