import Pako from "pako";

export function ToDeflatedBase64(materialJson: string)
{
    // return btoa(String.fromCharCode(...Deflate(materialJson)))
    const bin = Pako.deflate(materialJson,{to:"string"});
    return btoa(bin); 
}

export function FromDeflateBase64(base64: string) {
    let binaryString = atob(base64);
    // TODO: Danger: 压缩数据有问题，使用fflate或是pako@2.1.0会出现EOF/unknown compression method错误，必须要使用pako@1.0.11才行
    let data = Pako.inflate(binaryString as any, { to: "string" });
    // let data = U8ToStr(Deflate(binaryString));
    console.log("data", data);
    return data;
}