node-7z-threetwo
Version:
A CommonJs and ESM frontend to 7-Zip, downloads binaries in for Linux, Windows, and Mac OSX, with methods to create SFX self extracting 7z archives targeting different platforms.
39 lines (31 loc) • 1.08 kB
JavaScript
;
import when from 'when';
import Files from '../../util/esm/files.mjs';
import Run from '../../util/esm/run.mjs';
/**
* Delete content to an archive.
* @promise Delete
* @param archive {string} Path to the archive.
* @param files {string|array} Files to add.
* @param options {Object} An object of acceptable 7-zip switch options.
* @resolve {array} Arguments passed to the child-process.
* @reject {Error} The error as issued by 7-Zip.
*/
export default function (archive, files, options) {
return when.promise(function (resolve, reject) {
// Convert array of files into a string if needed.
files = Files(files);
// Create a string that can be parsed by `run`.
let command = '7za d "' + archive + '" ' + files;
// Start the command
Run(command, options)
// When all is done resolve the Promise.
.then(function (args) {
return resolve(args);
})
// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
return reject(err);
});
});
};