untitled notebook

node v14.20.0
version: 1.0.0
endpointsharetweet
const JSZip = require("jszip"); // Base64 of a gif image const imgData = "R0lGODdhBQAFAIACAAAAAP/eACwAAAAABQAFAAACCIwPkWerClIBADs="; var zip = new JSZip(); zip.file("Hello.txt", "Hello World\n"); var img = zip.folder("images"); img.file("smile.gif", imgData, {base64: true}); // Add google image into the zip file const googImg = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"; var request = require('request').defaults({ encoding: null }); request.get(googImg, function (error, response, body) { if (!error && response.statusCode == 200) { data = "data:" + response.headers["content-type"] + ";base64," + Buffer.from(body).toString('base64'); console.log(data); //img.file("googlelogo_color_272x92dp.png", data, {base64: true}); zip.generateAsync({type: 'nodebuffer'}) // blob -> nodebuffer .then(console.log); } }); /* This is browser code zip.generateAsync({type:"blob"}) .then(function(content) { // see FileSaver.js saveAs(content, "example.zip"); }); */
Loading…

no comments

    sign in to comment