ZJONSSON / node-unzipper

node.js cross-platform unzip using streams
Other
436 stars 116 forks source link

Unzipper removes executable permission of extracted file #216

Open tinesoft opened 4 years ago

tinesoft commented 4 years ago

Hi,

Thanks for this great library!

I'm using it to extract a zip containing an executable file (zip file can be found here: https://start.spring.io/starter.zip, file mvnwinside it has the executable flag)

But when extracting the zip with Unzipper, the flag is lost:

Here is the relevant code:

import fetch from 'node-fetch';
import {  Extract } from 'unzipper';

  public async generateProject(): Promise<void>{
        const response = await fetch('https://start.spring.io/starter.zip');

        return response.body.pipe(Extract({ path: 'path/to/extract' })).promise();
}

Any idea?

warerebel commented 4 years ago

I'm pretty certain there is no standardized cross-platform way of preserving file permissions in a zip archive? There are different implementations of this, but they're solution and platform specific.

tinesoft commented 4 years ago

Hi @warerebel ,

You mean in NodeJS?

Because when I unzip the archive on MacOs, or Windows, the execute permission is preserved just fine on the file that has it... Meaning the permission is preserved in the file within the archive. So it should be considered when extracting the files.

warerebel commented 3 years ago

The file permissions are an attribute of the filesystem on which the zip file was created, and they're system specific.

Windows NTFS, MacOS APFS, linux ext4 all have their own way of defining file permissions. When they unzip a file they try to translate the file permissions from the source FS to the target FS, they generally do it correctly, but not always.

NodeJS is generally does host independent things. This module is really about reading zip contents into streams and processing them. The stream has no concern for the file system, it is just file content, so it has no knowledge of either the source or the destination file system.

Someone could maybe write something to replicate this behaviour in a nodejs module, but it's a very niche use case. If you just need to execute the file natively on the host system you may as well use the host's native unzip client using node's child_process