node-unzipper icon indicating copy to clipboard operation
node-unzipper copied to clipboard

Unzipper removes executable permission of extracted file

Open tinesoft opened this issue 5 years ago • 3 comments

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?

tinesoft avatar Oct 18 '20 16:10 tinesoft

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.

warerebel avatar Oct 23 '20 13:10 warerebel

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.

tinesoft avatar Oct 23 '20 13:10 tinesoft

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

warerebel avatar Oct 23 '20 13:10 warerebel