Skip to content

Instantly share code, notes, and snippets.

@madaster97
Last active February 19, 2021 03:39
Show Gist options
  • Save madaster97/718bce53ad219f843e46324ef2b275fd to your computer and use it in GitHub Desktop.
Save madaster97/718bce53ad219f843e46324ef2b275fd to your computer and use it in GitHub Desktop.
Deflate SHC by Gzip
const zlib = require('zlib');
const Got = require('got').default;
const { promisify } = require('util');
const gzipRaw = promisify(zlib.gzip);
const minifiedUrl = 'https://smarthealth.cards/examples/example-00-c-jws-payload-minified.json';
async function deflateByGzip(string) {
const gzipped = await gzipRaw(string);
return gzipped.slice(10, gzipped.length - 8);
}
(async () => {
const minifiedPayload = (await Got.get(minifiedUrl)).body;
const deflated = await deflateByGzip(minifiedPayload);
const inflated = zlib.inflateRawSync(deflated);
console.log(inflated.toString());
})();
{
"name": "@madaster97/gzip-deflate-test",
"version": "1.0.0",
"description": "A simple gist to show gzip's use for deflation",
"main": "index.js",
"dependencies": {
"got": "^11.8.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Adam Strickland",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment