Comments (9)
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.
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.
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.
Thanks. I'll give it a shot. Appreciate your time.
from jszip.
@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.
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.
The need to convert some ArrayBuffer into a Buffer here is yet another effect of nodejs/node-v0.x-archive#4742 wontfixed.
from jszip.
I had the same problem. Instead of using jszip I'm using this and is working fine.
from jszip.
the problem is that jszip produces a pkzip file (4.5) and many archival programs only support 2.1
from jszip.
Related Issues (20)
- Error: Corrupted zip or bug: expected 19 records in central dir, got 0 HOT 4
- its not generating a password protected zip file is it a bug it directly opening file without asking password HOT 2
- How to asynchronously zip files using generateInternalStream method
- setImmediate function is been hijack by SinonJS package when it's installed on the same project as well
- Microsoft font licenses
- zipobject internalstream method not present in type definition file
- Reading blob on NodeJs fails HOT 2
- Fortify scan finds Insecure Randomness vulnerability in jszip.js, line 11488
- Fortify scan finds HTML5: Overly Permissive Message Posting Policy in jszip.js line 11477 and 11504 HOT 1
- Using Jszip in Angular to export 1-2 MB files considerably slows down UI HOT 2
- linebreak issues in windows text files HOT 1
- Byte alignment of resulting zip archive
- Missing folders when trying to extract files which are compressed using native compression software of Windows HOT 1
- Unable to open docx file in Node
- Same zip different zipContents when loadAsync
- JSZip v3.10+ breaks in some sandboxed browser environment because dependency setimmediate breaks HOT 1
- Can we generate LF instead of CRLF
- Reading Folder Doesn't Work
- Large zip file breaks with loadAsync
- Math.random() usage
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jszip.