Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unzip error [Error: invalid signature: 0xff000001]

Im using the following library for node unzip https://github.com/EvanOxfeld/node-unzip

The code which I use is

var extractor = unzip.Extract({
                path: 'C://TestFolder//TestZip'
            }).on('close', function () {
              console.log("Success to unzip");
            }).on('error', function (err) {
                console.log("error to unzip", err);
            });
            req.pipe(extractor);

The problem that In some zip file Im getting the error (in others its works fine) [Error: invalid signature: 0x8080014] [Error: invalid signature: 0x83870008] ....

This error doesnt give a lot info... searching the web I found this https://github.com/EvanOxfeld/node-unzip/issues/41

And install and require the unzip2 package instead of unzip , the issue now that Im getting the following error unzip Error: invalid signature: 0xff000001

I use the same code for unzip and unzip2 (which I provided in the post above),do I need to use it different? any hints how to solve it?

UPDATE

I send the zip file from postman like following enter image description here

like image 328
07_05_GuyT Avatar asked Nov 24 '15 14:11

07_05_GuyT


3 Answers

You can temporary save the ZIP file on your disk, and then extract it using adm-zip.

Here is a sample code:


Client Side:

<form action="/upload" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

Server Side

Using multer to save the uploaded file, and adm-zip to extract it. You need to install both:

npm install --save multer
npm install --save adm-zip

After installing here an example of using them together:

var multer=require('multer')   // a module for saving file from form.
var AdmZip = require('adm-zip'); // a module for extracting files
var express=require('express')  // module for receving HTTP traffic
var app=express()

var upload = multer({ dest: 'uploads/' })

app.post('/upload',upload.single('fileToUpload'),function(req,res){
   console.log('The file uploaded to:' + req.file.path)
   var zip = new AdmZip(req.file.path); 
   zip.extractAllTo( "/detination_folder/");
})

Information about the modules I used:

https://github.com/expressjs/multer , https://github.com/cthackers/adm-zip

like image 75
Aminadav Glickshtein Avatar answered Nov 16 '22 16:11

Aminadav Glickshtein


Node-unzip2 patches this problem.

example :

var readStream = fs.createReadStream('path/to/archive.zip');
var writeStream = fstream.Writer('output/path');

readStream
  .pipe(unzip.Parse())
  .pipe(writeStream)
like image 36
l3est Avatar answered Nov 16 '22 18:11

l3est


Try your unzip solution, but for receiving the binary data, attach this middleware and then get your file from req.rawBody:

app.use(function(req, res, next) {
  var data = new Buffer('');
  req.on('data', function(chunk) {
      data = Buffer.concat([data, chunk]);
  });
  req.on('end', function() {
    req.rawBody = data;
    next();
  });
});
like image 2
Jairo Avatar answered Nov 16 '22 16:11

Jairo