Giter VIP home page Giter VIP logo

Comments (9)

dduponchel avatar dduponchel commented on June 30, 2024

The resulting zip file contains your content as a base64 string.

$ base64 -d jsd-papuxetada.zip > decoded.zip
$ zipinfo decoded.zip
Archive:  decoded.zip
Zip file size: 224 bytes, number of entries: 2
drwx---     2.0 fat        0 b- stor 13-Mar-25 13:32 /tmp/
drwx---     2.0 fat        0 b- stor 13-Mar-25 13:32 /tmp/jsd-papuxetada/
2 files, 0 bytes uncompressed, 0 bytes compressed:  0.0%

The issue comes from zip.generate(). Without argument, this is the same as zip.generate({type:"base64"}) (it is an interesting default value for the location.href="data:application/zip;base64,"+content trick).
You should try zip.generate({type:"uint8array"}) or zip.generate({type:"arraybuffer"}) :-)

from jszip.

commadelimited avatar commadelimited commented on June 30, 2024

Tried both of those options and got the same result. Each time I ran it, it still resulted in a *.cpgz file instead of the directory I was expecting.

Here's what I tried:

Encoded with uint8array

base64 jsd-qidecahoyo.zip > decoded.zip

zipinfo decoded.zip
[decoded.zip]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
zipinfo:  cannot find zipfile directory in one of decoded.zip or
          decoded.zip.zip, and cannot find decoded.zip.ZIP, period.

zipinfo jsd-qidecahoyo.zip
[jsd-qidecahoyo.zip]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
zipinfo:  cannot find zipfile directory in one of jsd-qidecahoyo.zip or
          jsd-qidecahoyo.zip.zip, and cannot find jsd-qidecahoyo.zip.ZIP, period.
Encoded with arraybuffer

base64 jsd-fowejeveli.zip > decoded2.zip

zipinfo decoded2.zip
[decoded2.zip]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
zipinfo:  cannot find zipfile directory in one of decoded2.zip or
          decoded2.zip.zip, and cannot find decoded2.zip.ZIP, period.

zipinfo jsd-fowejeveli.zip
[decoded2.zip]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
zipinfo:  cannot find zipfile directory in one of decoded2.zip or
          decoded2.zip.zip, and cannot find decoded2.zip.ZIP, period.

from jszip.

dduponchel avatar dduponchel commented on June 30, 2024

It seems that nodejs method writeFileSync don't take an ArrayBuffer for buffer but transforms it to a string : the generated file contains [object ArrayBuffer].

Try to convert the ArrayBuffer into a Buffer :

var output = zip.generate({type:"arraybuffer"}),
    buffer = new Buffer(output.byteLength);

for (var i = 0; i < buffer.length; ++i) {
    buffer[i] = output[i];
}
fs.writeFileSync(baseDir + filename, buffer);

from jszip.

commadelimited avatar commadelimited commented on June 30, 2024

Thanks. I'll give it a shot. Appreciate your time.

from jszip.

commadelimited avatar commadelimited commented on June 30, 2024

@dduponchel Right on, that's really close. The zip file is extracting properly now, but the ZIP file itself is empty. The documentation itself doesn't explicitly say that it will add the contents of a directory along with the folder itself, but that's what most people would assume. I think I'm just going to go a diff route and dump all the files into one directory. Then I can loop over them and add each by itself.

from jszip.

dduponchel avatar dduponchel commented on June 30, 2024

JSZip is designed to work in a browser. It works in nodejs but you will lack some things like the support of Buffer or utilities to recursively read a folder.

Maybe we should add some explanations in the documentation.

from jszip.

Mithgol avatar Mithgol commented on June 30, 2024

The need to convert some ArrayBuffer into a Buffer here is yet another effect of nodejs/node-v0.x-archive#4742 wontfixed.

from jszip.

p1nox avatar p1nox commented on June 30, 2024

I had the same problem. Instead of using jszip I'm using this and is working fine.

from jszip.

dannydulai avatar dannydulai commented on June 30, 2024

the problem is that jszip produces a pkzip file (4.5) and many archival programs only support 2.1

from jszip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.