Why JSZip can't create blob file?
Asked Answered
T

1

6

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 ?

Touter answered 13/6, 2019 at 15:29 Comment(3)
Possible duplicate of Node.js can´t create Blobs?Sculpture
This topic does not seems to be useful in my case because I'm not trying to create a Blob but trying to create a ZIP from files. If you can precise how it can help me :) ThanksTouter
There is a github issue on the exact same problem. It has been wrongfully closed.Maddis
M
13

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);
Maddis answered 13/6, 2019 at 16:38 Comment(1)
nodebuffer YES!!System

© 2022 - 2024 — McMap. All rights reserved.