// /** // * @module other-helper respec // * // * we gotta test our other-helper compression functions. Thanks for the help // * Gemini. // */ // // import { cwd, chdir, } from 'node:process'; // // import { statSync } from 'node:fs'; // // import { mkdir, } from 'node:fs/promises'; // // import { ChildProcess, exec, ExecException } from 'node:child_process'; // import * as pathUtils from 'path'; // import { // firstOfAll, firstOfEach, ifWe, ifWeMight, iReckon, // lastOfAll, lastOfEach, respecfully, respecfullyDear // } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs'; // const maam = `[${import.meta.url}]`, sir = maam; // import { // extractErrorMsg, // } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs'; // import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs'; // import { compressIbGib, compressIbGibGraphToString, decompressIbGibGraphFromString } from './other-helper.mjs'; // import { FlatIbGibGraph } from './graph-types.mjs'; // /** // * for verbose logging // */ // const logalot = GLOBAL_LOG_A_LOT; // change this when you want to turn off verbose logging // const lcFile: string = `[${pathUtils.basename(import.meta.url)}]`; // const compressDecompressTestName = `compress/decompress dependency graph`; // await respecfully(maam, compressDecompressTestName, async () => { // await ifWe(maam, `get info...`, async () => { // const lc = `[${compressDecompressTestName}]`; // try { // if (logalot) { console.log(`${lc} Creating a sample FlatIbGibGraph...`); } // const originalGraph: FlatIbGibGraph = { // "root^gib": { // ib: "root", // gib: "gib", // rel8ns: { "child": ["data_node^gib", "binary_node^gib"] }, // data: { message: "This is the root node" } // }, // "data_node^gib": { // ib: "data_node", // gib: "gib", // rel8ns: undefined, // data: { a: 1, b: "hello", c: { nested: true } } // }, // "binary_node^gib": { // ib: "binary_node", // gib: "gib", // rel8ns: undefined, // data: new Uint8Array(Array.from({ length: 1024 }, (_, i) => i % 256)) // A larger 1KB binary blob // } // }; // // --- Step 1: Get original size --- // // A rough estimate by stringifying the object (doesn't account for binary data well) // const roughOriginalSize = JSON.stringify(originalGraph).length; // if (logalot) { console.log(`${lc} Rough original size (JSON string): ~${roughOriginalSize} bytes`); } // // --- Step 2: Compress to Blob --- // if (logalot) { console.log(`${lc} Compressing to Blob...`); } // const compressedBlob = await compressIbGib(originalGraph); // if (logalot) { console.log(`${lc} ✅ Compressed Blob size: ${compressedBlob.size} bytes`); } // // --- Step 3: Compress to String --- // if (logalot) { console.log(`${lc} Compressing to Base64 String...`); } // const compressedString = await compressIbGibGraphToString({ graph: originalGraph }); // if (logalot) { console.log(`${lc} ✅ Compressed Base64 String size: ${compressedString.length} bytes`); } // // --- Verification --- // const sizeRatio = ((compressedString.length / compressedBlob.size) * 100).toFixed(2); // // const sizeRatio = ((compressedString.length / compressedBlob.size - 1) * 100).toFixed(2); // if (logalot) { console.log(`${lc} (String is ~${sizeRatio}% larger than Blob)`); } // // console.log(`${lc} (String is ~${((compressedString.length / compressedBlob.size - 1) * 100).toFixed(1)}% larger than Blob)`); // // --- Step 4: Decompress from String and verify --- // if (logalot) { console.log(`${lc} Decompressing from Base64 string...`); } // const decompressedGraph = await decompressIbGibGraphFromString({ compressedBase64: compressedString }); // const originalBinaryLength = (originalGraph["binary_node^gib"].data as Uint8Array).length; // const decompressedBinaryLength = (decompressedGraph["binary_node^gib"].data as Uint8Array).length; // if (logalot) { console.log(`${lc} Decompression complete.`); } // iReckon(maam, decompressedBinaryLength).asTo('decompressedBinaryLength is the same as the originalBinaryLength').isGonnaBe(originalBinaryLength); // } catch (error) { // console.error(`${lcFile} ${extractErrorMsg(error)}`); // throw error; // } // }); // });