Skip to content

Instantly share code, notes, and snippets.

@Victor-Smith-Dev
Last active March 7, 2022 20:46
Show Gist options
  • Save Victor-Smith-Dev/89fd7d352ff81ced0741e6ace4a51e49 to your computer and use it in GitHub Desktop.
Save Victor-Smith-Dev/89fd7d352ff81ced0741e6ace4a51e49 to your computer and use it in GitHub Desktop.
Extract 7zip file on NodeJs

Extract 7zip file on NodeJs

This is the default option

import Seven from 'node-7z'; // or const Seven = require('node-7z');

const extract = Seven.extractFull('./archive.7z', './output/dir/', {
  $progress: true
});

extract.on('data', function (data) {
  doStuffWith(data)
});

extract.on('progress', function (progress) {
  doStuffWith(progress)
});

extract.on('end', function () {
  extract.info.get('Folders') //? '4'
});

extract.on('error', (err) => handleError(err));

You should have the a 7-Zip executable (v16.02 or greater) available in your system.

  • On Debian and Ubuntu install the p7zip-full package or use 7-Zip 21.02 alpha or higher
  • On Mac OSX use Homebrew brew install p7zip
  • On Windows get 7-Zip from 7-Zip download page.

By default the module calls the 7z binary, it should be available in your PATH.

An alternative is to add the 7zip-bin module to your project. This module contains an up-to-date version of 7-Zip for all available plaforms. Then you can do:

import sevenBin from '7zip-bin'
import { extractFull } from 'node-7z'

const pathTo7zip = sevenBin.path7za
const seven = extractFull('./archive.7z', './output/dir/', {
  $bin: pathTo7zip
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment