Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading blob on NodeJs fails #899

Open
Michael-1 opened this issue Jun 1, 2023 · 2 comments · May be fixed by #903
Open

Reading blob on NodeJs fails #899

Michael-1 opened this issue Jun 1, 2023 · 2 comments · May be fixed by #903

Comments

@Michael-1
Copy link

I’m executing the example code for get a file with an Ajax call on NodeJS 18:

"use strict";

fetch("/jszip/test/ref/text.zip")       // 1) fetch the url
    .then(function (response) {                       // 2) filter on 200 OK
        if (response.status === 200 || response.status === 0) {
            return Promise.resolve(response.blob());
        } else {
            return Promise.reject(new Error(response.statusText));
        }
    })
    .then(JSZip.loadAsync)                            // 3) chain with the zip promise
    .then(function (zip) {
        return zip.file("Hello.txt").async("string"); // 4) chain with the text content promise
    })
    .then(function success(text) {                    // 5) display the result
        $("#fetch").append($("<p>", {
            "class": "alert alert-success",
            text: "loaded, content = " + text
        }));
    }, function error(e) {
        $("#fetch").append($("<p>", {
            "class": "alert alert-danger",
            text: e
        }));
    });

The code fails:

jszip@3.10.1/node_modules/jszip/lib/utils.js:479
                new Error("Can't read the data of '" + name + "'. Is it " +
                ^
Error: Can't read the data of 'the loaded zip file'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?
@Michael-1 Michael-1 changed the title Reading blob on nodejs fails Reading blob on NodeJs fails Jun 1, 2023
@Michael-1
Copy link
Author

Using response.arrayBuffer() instead of response.blob() makes it work.

@UlyssesZh
Copy link

UlyssesZh commented Jul 26, 2023

I found this bug today. Here is a shorter reproducing sample:

npm i jszip
echo 'Hello World' > hello.txt && zip hello.zip hello.txt
node -e "require('jszip').loadAsync(new Blob([require('fs').readFileSync('hello.zip')]));"
/home/ulysses/temp/jszip-test/node_modules/jszip/lib/utils.js:479
                new Error("Can't read the data of '" + name + "'. Is it " +
                ^

Error: Can't read the data of 'the loaded zip file'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?
    at /home/ulysses/temp/jszip-test/node_modules/jszip/lib/utils.js:479:17

Node.js v18.16.0

Version info:

  • Zip: 3.0
  • Node.js: 18.16.0
  • jszip: 3.10.1

UlyssesZh added a commit to UlyssesZh/jszip that referenced this issue Jul 26, 2023
@UlyssesZh UlyssesZh linked a pull request Jul 26, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants