I was trying JSZip on NodeJS to create some ZIP file but i'm facing an issue.
I'm using the code proposed by JSZip :
var JSZip = require('JSZip')
var zip = new JSZip()
zip.file("Hello.txt", "Hello World\n")
zip.generateAsync({type:"blob"}).then(function(content) {
//do things here
});
Currently the code throw an error on generateAsync
UnhandledPromiseRejectionWarning: Error: blob is not supported by this platform
Did something need to be install or the data I set in zip.file should be in a certain format ?
JSZip throws this error at jszip/lib/utils.js:352:15
because of the value of support.blob
, defined by at jszip/lib/support.js
(lines 11 to 32). I don't know for your machine, but while trying to run this script in NodeJS, I've debugged it to the conclusion that JSZip detects blobs to be not supported because self
is not defined, so line 23 throws an error and support.blob
is set to false.
JSZip seems to support the Node Buffer type on Node though - the following doesn't throw any errors on my machine:
// JSZip v3.2.1
// NodeJS v8.10.0
// Ubuntu 18.04
const JSZip = require('jszip');
const zip = new JSZip();
zip.file('hello.txt', 'Hello world\n');
zip
.generateAsync({type: 'nodebuffer'}) // blob -> nodebuffer
.then(console.log);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With