Created
October 5, 2018 17:35
-
-
Save chinoto/a05c13539cbfef421708a0271269102b to your computer and use it in GitHub Desktop.
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 fs = require('fs-extra'); | |
const {gzip,ungzip:gunzip} = require('node-gzip'); | |
//const decoder = new require('string_decoder').StringDecoder('utf8'); | |
//const {toByteArray:b64dec,fromByteArray:b64enc} = require('base64-js'); | |
//const {encode:yEnc,decode:yDec} = require('yenc-stream'); | |
const qrI = require('qr-image'); | |
//const qrC = require('qrcode'); | |
async function encoder(jsonStr) { | |
//let jsonStr=await fs.readFile('/home/damian/Downloads/F8KKsSyF.txt','utf-8'); | |
let jsonGzip64=await gzip(jsonStr); | |
return qrI.imageSync(jsonStr,{ec_level:'L',type:'svg'}); | |
/* | |
let test=await gunzip((jsonGzip64)); | |
console.log( | |
jsonStr+'\n\n' | |
+jsonGzip64+'\n\n' | |
+`${jsonStr.length}:${jsonGzip64.length}:${(jsonGzip64.length/jsonStr.length*100)|0}%\n` | |
+(decoder.write(test)===jsonStr) | |
); | |
*/ | |
}; | |
const app = require('express')(); | |
app.get('/*',async (req,res)=>{ | |
res.send( | |
`<!DOCTYPE html> | |
<html><body style='width:30em;'> | |
${await encoder(decodeURIComponent(req.url.slice(1)))} | |
</body></html>`); | |
}); | |
app.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment