0

I'm trying to use node-7z in my Electron app to decrypt password protected zip files, but whenever I pass a password, I get an enoent error. I'm including 7zip-bin and the .7za file is present at the location and when I console.log 7zip-bin.path7za I'm getting a valid exe. If I extract a zip that does not have any password, there is no issues and I have ran npm install in both my project root and the node modules folder, is there anything else I am missing?

Thank you for your help.

const { extractFull } = require('node-7z')
const zipbin = require('7zip-bin')

let testFile = zipLocation + "/zip.zip";
    const pathTo7zip = zipbin.path7za;
    console.log(pathTo7zip); -->Returns .z7a file path
    const myStream = extractFull(testFile, installLocation, { password: 'password' }, { 
        $bin: pathTo7zip,
        $progress: true
    })
    myStream.on('error', (err) => handleError(err));
}

If I add a password using either p: or password: then I get the below error:

Error: spawn 7z ENOENT
    at notFoundError (***app\node_modules\cross-spawn\lib\enoent.js:6)
    at verifyENOENT (****app\node_modules\cross-spawn\lib\enoent.js:40)
    at ChildProcess.cp.emit (*****app\node_modules\cross-spawn\lib\enoent.js:27)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:272)

Without a password, I have no issues, but the whole reason I'm using node-7z is for zip/.7z encryption.

Zack Cain
  • 35
  • 7
  • Where does `installLocation` come from? It's not defined in the code snippet you've posted -- maybe that's the issue? – Alexander Leithner May 29 '21 at 10:30
  • Hi Alex, installLocation is a stored variable of the output location of the zip. Can't be that as it's working without the password, I've console.log out that too and it's valid. – Zack Cain May 29 '21 at 11:09
  • Any solution to this problem? I am getting the same error message – freecks Jul 07 '21 at 19:24
  • No I spent another 2 days trying to fix it and I had to give up. It's really frustrating as there aren't many good password protected zip libraries for nodejs/electron – Zack Cain Jul 08 '21 at 20:56

1 Answers1

0

This may be a little late, but in case somebody stumbles upon this post, like I did, here's the solution.

As mentioned in the answer here: electron-packager spawn ENOENT

  1. npm install fix-path (https://www.npmjs.com/package/fix-path)
  2. Import/require and run it inside your electron-main.js

const fixPath = require('fix-path');
// or
import fixPath from 'fix-path';

fixPath();

Reason why this happens kinda explained in the description of the package:

GUI apps on macOS don't inherit the $PATH defined in your dotfiles.

abfarid
  • 555
  • 6
  • 13