Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to use jszip in node.js

"use strict";

var fs = require("fs");
var JSZip = require("jszip");

// read a zip file
fs.readFile("test.zip", function(err, data) {
    if (err) throw err;
    JSZip.loadAsync(data).then(function (zip) {
        // ...
    });
});
// or
new JSZip.external.Promise(function (resolve, reject) {
    fs.readFile("test.zip", function(err, data) {
        if (err) {
            reject(e);
        } else {
            resolve(data);
        }
    });
}).then(function (data) {
    return JSZip.loadAsync(data);
})
.then(...)


// read a file and add it to a zip
fs.readFile("picture.png", function(err, data) {
    if (err) throw err;
    var zip = new JSZip();
    zip.file("picture.png", data);
});
// or
var contentPromise = new JSZip.external.Promise(function (resolve, reject) {
    fs.readFile("picture.png", function(err, data) {
        if (err) {
            reject(e);
        } else {
            resolve(data);
        }
    });
});
zip.file("picture.png", contentPromise);


// read a file as a stream and add it to a zip
var stream = fs.createReadStream("picture.png");
zip.file("picture.png", stream);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add base url as src in react native 
Javascript :: jquery ajax form submit example 
Javascript :: http delete angular 
Javascript :: nextjs getserversideprops 
Javascript :: js import and export 
Javascript :: regex quantifiers 
Javascript :: how to print in a same line in javascript 
Javascript :: array put value in index 
Javascript :: how to get width in javascript 
Javascript :: javascript string to number 
Javascript :: find text in label jquery 
Javascript :: react hook example 
Javascript :: loop through array react native 
Javascript :: react bootstrap cdn 
Javascript :: send json body http get flutter 
Javascript :: reload datatable without ajax 
Javascript :: js unique string array 
Javascript :: sequelize update sql 
Javascript :: filter an array of objects and match its key with values inside another array 
Javascript :: javascript scroll tracker 
Javascript :: 100vh mobile 
Javascript :: mock an api call in jest 
Javascript :: how to convert a string to react element in javascript 
Javascript :: addeventlistener javascript 
Javascript :: javascript crash course 
Javascript :: js get index of item in array 
Javascript :: react functional components 
Javascript :: javascript regex exact match 
Javascript :: what is redux 
Javascript :: usememo react 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =