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

Zip file is empty - sort of... #171

Open
moonlitSpider opened this issue Oct 12, 2016 · 17 comments
Open

Zip file is empty - sort of... #171

moonlitSpider opened this issue Oct 12, 2016 · 17 comments

Comments

@moonlitSpider
Copy link

Hi,

I've been wrestling with this issue for the last 2 hours and am convinced that I must be doing something woefully dumb.

I am trying to create a zip archive that contains exactly 1 file - a text (log) file. Shown below is my latest attempt, but I also tried the addLocalFile method described in the documentation.

In all cases the result is the same:

  1. The zip file is created
  2. When I point a web browser to it to cause standard browser download behavior, the zip file appears to be properly downloaded.
  3. But when I open the archive in Windows Explorer (Windows 2012 Server) either using standard Windows filesystem logic, or using 7-Zip, the zip is empty. Specifically,
  • In Explorer the zip file shows a length of 67K
  • When I double-click on it, it opens to the next level, showing the filename that I assigned, but it shows a type of "File Folder"
  • When I double-click again, it says "This folder is empty"

I should also point out that within the Linux (CentOS 6) shell, I can run the unzip command against the archive and it all works as expected.

So either I'm doing something wrong, or is there some dependency on Windows?

Thanks very much for your help.

-Paul

    fs.readFile(fqLogPath, function (err, buffer) {
            if (err)
            {
                console.log('FAILURE')
                return;
            }

            var zip = new AdmZip();
            zip.addFile(uniqueId + '.txt', buffer);
            zip.writeZip(__dirname + '/public/' + uniqueId + '.zip');
    });
@dondre
Copy link

dondre commented Oct 23, 2016

Running into this issue as well. I personally use WinRar and it's able to see the files, but other windows users are not. I was hoping this was a format issue that could be changed in the constructor. But since there's no replies perhaps this is an unresolved issue.

If that's the case then this is a deal breaker and I'll need to find another library.

@sangoon
Copy link

sangoon commented Feb 1, 2017

Hi guys i'm actually running into this issue to. Fighting with adm-zip for hours without much result.
This problem seems to only occurs in a Windows environment.

For what it's worth, here are the steps to reproduce it :

  1. Setup a new nodejs project with some dependencies adm-zip (and in my case bluebird but this is not required) put some random source files in an "input" folder
  2. write down the following code in a js file :
"use strict";

const Promise = require("bluebird");
const path = require("path");
const fs = Promise.promisifyAll(require("fs"));
const AdmZip = require("adm-zip");

const inputDirectory = path.join(__dirname, "input");
const zip = new AdmZip();

fs.readdirAsync(outputDirectory)
    .map(file => zip.addLocalFile(path.join(inputDirectory, file)))
    .then(() => zip.writeZip(path.join(__dirname, "latest.zip")));
  1. run the script
  2. open the new generated archive "latest.zip" and see entries as empty folders :/

@emazzu
Copy link

emazzu commented Feb 14, 2017

I work with ubuntu, and the file.zip generated said 564.8 kb, but when I want to open this, is open.

I don't know to do, I tryied use the the node module zlib, but I can't compress two files por example !!!

Regards
Eduardo

@dwightdegroff
Copy link

I have the same issue @moonlitSpider

@postatum
Copy link

I'm having this issue too. Both on Win and Linux

@avimak
Copy link

avimak commented Mar 15, 2017

Had the same issue on Mac OSX, turned out it was a missing attribute, see here #177
e.g.
zip.addFile(name, content, comment, 0400);
(or any other requested attr)

@niczak
Copy link

niczak commented Mar 28, 2017

@avimak How are you passing 'content' in that case? Is it a buffer from a local file or ... ?

@avimak
Copy link

avimak commented Mar 28, 2017

@niczak buffer (binary)

@niczak
Copy link

niczak commented Mar 28, 2017

Here is how I got around this issue:

var zip = new ADMZip();
var input = fs.readFileSync(pathToCSV);
zip.addFile('file_name_here.csv', input, '', 0644);
zip.writeZip(pathToZip);

^--- Works on Linux, OSX, Windows.

@suchendra
Copy link

suchendra commented Mar 31, 2017

@niczak Yeah, that's one of the way you can achieve it, but better one is, add following code in adm-zip.js code.

if (!attr) {

     if (entry.isDirectory)  {

		attr = (040755 << 16) | 0x10;
	}

           else {

	         attr = 0644 << 16;

	}

 }	

@StephaneNestor
Copy link

Can you explain where we should add that in the code ?

@suchendra
Copy link

suchendra commented Sep 28, 2017

In adm-zip.js

@EthraZa
Copy link

EthraZa commented Sep 29, 2017

@suchendra I'm facing this right now.
I have added the provided code to addFile function.

Before add the code, If I create the ZIP on Linux, it works, if I create it on Windows, it gets only the directory structure inside it, the files shows up as empty directories. I can see that structure on Linux, on Windows it is just empty zip file.

After I added the code and created the zip file on Windows, it works great on Linux, but still shows as empty on Windows bultin zip extractor and PHP 5.3 zip class.

The zip files are attached.
before.zip
after.zip

Zip created with this code on node 8.6.0 within nw.js 0.25.4 on Windows 10:

		var scope = this,
			tmp = temp.createWriteStream({suffix: '.zip'});

		if (sPath && oPrm) {
			try {
				var zip = new AdmZip();

				zip.addLocalFolder(sPath);
				zip.writeZip(tmp.path);

				scope.log.debug('zip_ok', `${tmp.path}`);
			} catch (e) {
				scope.log.debug('zip_error', `${tmp.path}`);
			}
		}

@suchendra
Copy link

There is no problem with the Node version. I can see your after.zip contains some text file. May be you should use some different zip extractor. Please try with other zip extractor and let me know.

@EthraZa
Copy link

EthraZa commented Oct 9, 2017

Hi, on my Linux server I may have this choice, on costumers Windows, no way.
Any ways, on the PHP side of things I found out what was happening.
I have to change this very old code from this:

while ($bFile = zip_read($rZip)) {
    $fname = zip_entry_name($bFile);
    $sFcontent = zip_entry_read($bFile, $bytes);
    file_put_contents($sPath.$fname, $sFcontent, LOCK_EX);
}

to this:

$fname = basename(zip_entry_name($bFile));

In other words I had to strip off the path from the file name.

The server code was working for all this years with an old version of Titanium Desktop Zip implementation and with AdmZip it never worked very well, now it is working with both zip files (before and after the patch), so it's good enough to me, I just wanted you to know.

Thank you.

@ceras-ella
Copy link

I saw the piece of code that's supposed to fix this in the latest version. I assume this issue can be closed? (maybe it will save others some time to check it)
And thank you for taking care of it :)

@Losses
Copy link

Losses commented Apr 2, 2022

Same issue, Windows Node.js.

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

No branches or pull requests