Last active
February 19, 2021 03:39
-
-
Save madaster97/718bce53ad219f843e46324ef2b275fd to your computer and use it in GitHub Desktop.
Deflate SHC by Gzip
This file contains 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
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()); | |
})(); |
This file contains 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
{ | |
"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