ZJONSSON / node-unzipper

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

error and finsish events are not triggert on password protected files with asar in it #188

Open Tobias-Keller opened 4 years ago

Tobias-Keller commented 4 years ago

i am trying to unzip a .zip file that has a .asar file in it. If i run unzipper i never reache the error or finish event if a .asar file is in it and the file is password protected. With other Fileformatsin it, or without password protection it runs nicely.

tryed to rename the asar file, but this is not working.

EDIT: I am using 7Zip to create the files with ZipCrypto, happens also with old winrar method.

is there any solution for this?

Here is my code:

extractPlugin('somePath', 'someOtherPath')
 .catch(error => { console.log(error) })
 .then(data => { console.log(data) });

function extractPlugin(path, realPluginDir){
return new Promise((resolve, reject) => {
        console.log('start unzipping');
        unzipper.Open.file(path)
            .then(directory => {
                directory.files[0]
                    .stream(['123'])
                    .pipe(fs.createWriteStream(realPluginDir + directory.files[0].path))
                    .on('error', () => {
                       console.log('error on unzipping);
                        reject();
                    })
                    .on('finish', () => {
                        console.log('successfully unzipping);
                        resolve(realPluginDir + directory.files[0].path);
                    })
            })
    });
}

console output:

->  node "D:\pathTo\extractPlugins.js"                                                                                     

start unzipping

{ signature: 33639248,
  versionMadeBy: 63,
  versionsNeededToExtract: 20,
  flags: 1,
  compressionMethod: 8,
  lastModifiedTime: 28775,
  lastModifiedDate: 20588,
  crc32: 3645913360,
  compressedSize: 24409564,
  uncompressedSize: 34142450,
  fileNameLength: 22,
  extraFieldLength: 36,
  fileCommentLength: 0,
  diskNumber: 0,
  internalFileAttributes: 0,
  externalFileAttributes: 32,
  offsetToLocalFileHeader: 0,
  lastModifiedDateTime: 2020-03-12T14:03:14.000Z,
  pathBuffer:
   <Buffer 63 6f 6e 65 78 75 73 46 6f 72 57 69 6e 6c 69 6e 65 2e 61 73 61 72>,
  path: 'myAsar.asar',
  isUnicode: 1,
  extra: {},
  comment: '',
  type: 'File',
  stream: [Function],
  buffer: [Function] }
doredu commented 4 years ago

I think the problem is the size of the file. I observed that if the file size is big and the zip is password protected the .buffer/.stream(password) has huge delays (i tested of the same archive but without password and it's instant extraction).

I have no solution for this problem.