Created
April 27, 2023 14:40
-
-
Save Shtille/a9a1cff95fdd03bc5da68b6cbc4245c7 to your computer and use it in GitHub Desktop.
Inflates file content and encodes as base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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