question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Zip file is empty - sort of...

See original GitHub issue

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');
    });

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:9
  • Comments:17

github_iconTop GitHub Comments

2reactions
suchendracommented, Oct 9, 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;

	}

 }	
2reactions
sangooncommented, 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 😕
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix ZIP File Is Empty Problem on Windows?
Go to Start menu and click Command Prompt (Admin) · Switch to (change directory to) folder where the corrupted ZIP file is saved...
Read more >
.zip file download appears empty - Microsoft Community
.zip file download appears empty · Press windows key + C together and click on search. · In search box type Internet Explorer,...
Read more >
ZIP FILE WILL NOT OPEN OR IS EMPTY - ATP Textures
Go to Start menu and click Command Prompt (Admin) · Switch to (change directory to) folder where the corrupted ZIP file is saved...
Read more >
How to open a .ZIP file that is not empty, but Windows shows it ...
I stumbled upon this issue couple of times and the reason was that the zip file was not downloaded fully (the browser will...
Read more >
Why some downloaded Zip files show empty folders after ...
One of the scenarios where the zip file that you have downloaded can show empty folders involves the presence of viruses in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found