Skip to content

Instantly share code, notes, and snippets.

@Shtille
Created April 27, 2023 14:40
Show Gist options
  • Save Shtille/a9a1cff95fdd03bc5da68b6cbc4245c7 to your computer and use it in GitHub Desktop.
Save Shtille/a9a1cff95fdd03bc5da68b6cbc4245c7 to your computer and use it in GitHub Desktop.
Inflates file content and encodes as base64
/**
* To use this module simply run:
* ~~~{.sh}
* node pack_file.js
* ~~~
*/
const fs = require('fs');
const zlib = require('zlib');
const kJsonFile = 'file.json';
const kDeflatedFile = 'file_packed.txt';
const kInflatedFile = 'file_unpacked.json';
var data = fs.readFileSync(kJsonFile, 'utf8');
var deflated = zlib.deflateSync(data).toString('base64');
fs.writeFileSync(kDeflatedFile, deflated);
// Test written data
deflated = fs.readFileSync(kDeflatedFile, 'utf8');
var inflated = zlib.inflateSync(Buffer.from(deflated, 'base64')).toString();
fs.writeFileSync(kInflatedFile, inflated);
if (inflated != data)
console.warn('test failed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment