Skip to content

Commit

Permalink
adding back changes to use binaries included
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Feb 5, 2018
1 parent e93680e commit ef01e82
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 17 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
before_install:
- sudo apt-get update -qq
- sudo apt-get install -y p7zip-full
language: node_js
node_js:
- '6'
Expand Down
5 changes: 3 additions & 2 deletions lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var u = {
files : require('../util/files'),
run : require('../util/run'),
switches: require('../util/switches'),
// path : require('../util/path'),
path : require('../util/path')
};

/**
Expand All @@ -19,12 +19,13 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, files, options) {
var command = u.path(options);
return when.promise(function (resolve, reject, progress) {

// Convert array of files into a string if needed.
files = u.files(files);

var command = '7z a "' + archive + '" ' + files;
command += ' a "' + archive + '" ' + files;

// Start the command
u.run(command, options)
Expand Down
4 changes: 3 additions & 1 deletion lib/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var u = {
files : require('../util/files'),
run : require('../util/run'),
switches: require('../util/switches'),
path : require('../util/path')
};

/**
Expand All @@ -16,13 +17,14 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, files, options) {
var command = u.path(options);
return when.promise(function (resolve, reject) {

// Convert array of files into a string if needed.
files = u.files(files);

// Create a string that can be parsed by `run`.
var command = '7z d "' + archive + '" ' + files;
command += ' d "' + archive + '" ' + files;

// Start the command
u.run(command, options)
Expand Down
6 changes: 4 additions & 2 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var path = require('path');
var when = require('when');
var u = {
run : require('../util/run'),
switches: require('../util/switches')
switches: require('../util/switches'),
path : require('../util/path')
};

/**
Expand All @@ -17,10 +18,11 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, dest, options) {
var command = u.path(options);
return when.promise(function (resolve, reject, progress) {

// Create a string that can be parsed by `run`.
var command = '7z e "' + archive + '" -o"' + dest + '" ';
command += ' e "' + archive + '" -o"' + dest + '" ';

// Start the command
u.run(command, options)
Expand Down
6 changes: 4 additions & 2 deletions lib/extractFull.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var path = require('path');
var when = require('when');
var u = {
run : require('../util/run'),
switches: require('../util/switches')
switches: require('../util/switches'),
path : require('../util/path')
};

/**
Expand All @@ -17,10 +18,11 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, dest, options) {
var command = u.path(options);
return when.promise(function (resolve, reject, progress) {

// Create a string that can be parsed by `run`.
var command = '7z x "' + archive + '" -o"' + dest + '" ';
command += ' x "' + archive + '" -o"' + dest + '" ';

// Start the command
u.run(command, options)
Expand Down
13 changes: 13 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
'use strict';

function makeExecutable(){
var FS = require("fs");
var Path = require("path");
var macosversion = (process.platform == "darwin") ? require('macos-release').version : '';
var binarypath = Path.join(__dirname, "..","binaries", macosversion == '' ? process.platform : process.platform, macosversion );
var filePath = Path.join(binarypath, process.platform === "win32" ? '7za.exe' : '7za');
if (process.platform !== "win32") {
FS.chmodSync(filePath, 755);
}
return;
}

var Zip = function () {};

Zip.prototype.add = require('./add');
Expand All @@ -11,3 +23,4 @@ Zip.prototype.test = require('./test');
Zip.prototype.update = require('./update');

module.exports = Zip;
makeExecutable();
6 changes: 4 additions & 2 deletions lib/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var path = require('path');
var when = require('when');
var u = {
run : require('../util/run'),
switches: require('../util/switches')
switches: require('../util/switches'),
path : require('../util/path')
};

/**
Expand All @@ -16,6 +17,7 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, options) {
var command = u.path(options);
return when.promise(function (resolve, reject, progress) {

var spec = {};
Expand All @@ -24,7 +26,7 @@ module.exports = function (archive, options) {
/* jshint maxlen: 80 */

// Create a string that can be parsed by `run`.
var command = '7z l "' + archive + '" ';
command += ' l "' + archive + '" ';

var buffer = ""; //Store imcomplete line of a progress data.
// Start the command
Expand Down
6 changes: 4 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var path = require('path');
var when = require('when');
var u = {
run : require('../util/run'),
switches: require('../util/switches')
switches: require('../util/switches'),
path : require('../util/path')
};

/**
Expand All @@ -16,10 +17,11 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, options) {
var command = u.path(options);
return when.promise(function (resolve, reject, progress) {

// Create a string that can be parsed by `run`.
var command = '7z t "' + archive + '"';
command += ' t "' + archive + '"';

// Start the command
u.run(command, options)
Expand Down
6 changes: 4 additions & 2 deletions lib/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
switches : require('../util/switches')
switches : require('../util/switches'),
path : require('../util/path')
};

/**
Expand All @@ -17,10 +18,11 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, files, options) {
var command = u.path(options);
return when.promise(function (resolve, reject, progress) {

// Create a string that can be parsed by `run`.
var command = '7z u "' + archive + '" "' + files + '"';
command = ' u "' + archive + '" "' + files + '"';

// Start the command
u.run(command, options)
Expand Down
7 changes: 5 additions & 2 deletions util/path.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
var path = require('path');

module.exports = function (options) {

Expand All @@ -7,8 +8,10 @@ module.exports = function (options) {

if (options.path) {
return options.path;
} else {
return '7z';
} else {
var macversion = (process.platform == "darwin") ? require('macos-release').version : '';
var binarypath = path.join(__dirname, '..','binaries', (macversion=='') ? process.platform : process.platform, macversion);
return path.join(binarypath, process.platform === "win32" ? '7za.exe' : '7za');
}

} catch (e) {
Expand Down
11 changes: 10 additions & 1 deletion util/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ var utilSwitches = require('./switches');
* @reject {Error} The error issued by 7-Zip.
* @reject {number} Exit code issued by 7-Zip.
*/
module.exports = function (command, switches) {
module.exports = function (command, switches) {

// add platform binary to environment path
var envPath = process.env.path;
if (envPath.indexOf('7za') < 0) {
var macos = (process.platform == "darwin") ? require('macos-release').version : '';
var pathto7z = path.join(__dirname, "..","binaries", macos == '' ? process.platform : process.platform, macos );
process.env.path += (envPath[envPath.length -1] === ';') ? pathto7z : ';' + pathto7z;
}

return when.promise(function (fulfill, reject, progress) {

// Parse the command variable. If the command is not a string reject the
Expand Down

0 comments on commit ef01e82

Please sign in to comment.