Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Feb 6, 2018
1 parent 60b7ccf commit 89f8262
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 49 deletions.
10 changes: 5 additions & 5 deletions lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, files, options) {
return when.promise(function (resolve, reject, progress) {
return when.promise(function(resolve, reject, progress) {

// Convert array of files into a string if needed.
files = u.files(files);
Expand All @@ -38,9 +38,9 @@ module.exports = function(archive, files, options) {
// When a stdout is emitted, parse each line and search for a pattern. When
// the pattern is found, extract the file (or directory) name from it and
// pass it to an array. Finally returns this array in the progress function.
.progress(function (data) {
.progress(function(data) {
var entries = [];
data.split('\n').forEach(function (line) {
data.split('\n').forEach(function(line) {
if (line.substr(0, 13) === 'Compressing ') {
entries.push(line.substr(13, line.length).replace(path.sep, '/'));
}
Expand All @@ -49,12 +49,12 @@ module.exports = function(archive, files, options) {
})

// When all is done resolve the Promise.
.then(function (args) {
.then(function(args) {
return resolve(args);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
.catch(function(err) {
return reject(err);
});

Expand Down
6 changes: 3 additions & 3 deletions lib/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, files, options) {
return when.promise(function (resolve, reject) {
return when.promise(function(resolve, reject) {

// Convert array of files into a string if needed.
files = u.files(files);
Expand All @@ -36,12 +36,12 @@ module.exports = function(archive, files, options) {
u.run(command, options)

// When all is done resolve the Promise.
.then(function (args) {
.then(function(args) {
return resolve(args);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
.catch(function(err) {
return reject(err);
});

Expand Down
8 changes: 4 additions & 4 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, dest, options) {
return when.promise(function (resolve, reject, progress) {
return when.promise(function(resolve, reject, progress) {

// Create a string that can be parsed by `run`.
try {
Expand All @@ -37,7 +37,7 @@ module.exports = function(archive, dest, options) {
// the pattern is found, extract the file (or directory) name from it and
// pass it to an array. Finally returns this array.
// Also check if a file is extracted using an Unsupported Method of 7-Zip.
.progress(function (data) {
.progress(function(data) {

var entries = [];
var isUnsupportedMethod = (data.search('Unsupported Method'))
Expand All @@ -56,12 +56,12 @@ module.exports = function(archive, dest, options) {
})

// When all is done resolve the Promise.
.then(function (args) {
.then(function(args) {
return resolve(args);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
.catch(function(err) {
return reject(err);
});

Expand Down
10 changes: 5 additions & 5 deletions lib/extractFull.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, dest, options) {
return when.promise(function (resolve, reject, progress) {
return when.promise(function(resolve, reject, progress) {

// Create a string that can be parsed by `run`.
try {
Expand All @@ -37,7 +37,7 @@ module.exports = function(archive, dest, options) {
// the pattern is found, extract the file (or directory) name from it and
// pass it to an array. Finally returns this array.
// Also check if a file is extracted using an Unsupported Method of 7-Zip.
.progress(function (data) {
.progress(function(data) {

var entries = [];
var isUnsupportedMethod = (data.search('Unsupported Method'))
Expand All @@ -48,7 +48,7 @@ module.exports = function(archive, dest, options) {
}

var entries = [];
data.split('\n').forEach(function (line) {
data.split('\n').forEach(function(line) {
if (line.substr(0, 12) === 'Extracting ') {
entries.push(line.substr(12, line.length).replace(path.sep, '/'));
}
Expand All @@ -57,12 +57,12 @@ module.exports = function(archive, dest, options) {
})

// When all is done resolve the Promise.
.then(function (args) {
.then(function(args) {
return resolve(args);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
.catch(function(err) {
return reject(err);
});

Expand Down
10 changes: 5 additions & 5 deletions lib/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, options) {
return when.promise(function (resolve, reject, progress) {
return when.promise(function(resolve, reject, progress) {

var spec = {};
/* jshint maxlen: 130 */
Expand All @@ -41,7 +41,7 @@ module.exports = function(archive, options) {
// When a stdout is emitted, parse each line and search for a pattern. When
// the pattern is found, extract the file (or directory) name from it and
// pass it to an array. Finally returns this array.
.progress(function (data) {
.progress(function(data) {
var entries = [];

// Last progress had an incomplete line. Prepend it to the data and clear
Expand All @@ -51,7 +51,7 @@ module.exports = function(archive, options) {
buffer = "";
}

data.split('\n').forEach(function (line) {
data.split('\n').forEach(function(line) {

// Populate the tech specs of the archive that are passed to the
// resolve handler.
Expand Down Expand Up @@ -96,12 +96,12 @@ module.exports = function(archive, options) {
})

// When all is done resolve the Promise.
.then(function () {
.then(function() {
return resolve(spec);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
.catch(function(err) {
return reject(err);
});

Expand Down
8 changes: 4 additions & 4 deletions lib/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var u = {
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, files, options) {
return when.promise(function (resolve, reject, progress) {
return when.promise(function(resolve, reject, progress) {

// Create a string that can be parsed by `run`.
try {
Expand All @@ -36,7 +36,7 @@ module.exports = function(archive, files, options) {
// When a stdout is emitted, parse each line and search for a pattern. When
// the pattern is found, extract the file (or directory) name from it and
// pass it to an array. Finally returns this array.
.progress(function (data) {
.progress(function(data) {
var entries = [];
data.split('\n').forEach(function (line) {
if (line.substr(0, 13) === 'Compressing ') {
Expand All @@ -47,12 +47,12 @@ module.exports = function(archive, files, options) {
})

// When all is done resolve the Promise.
.then(function () {
.then(function() {
return resolve();
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
.catch(function(err) {
return reject(err);
});

Expand Down
20 changes: 10 additions & 10 deletions test/lib/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ var add = require('../../lib/add');
var path = require('../../util/path');
var _7zcmd = path();

describe('Method: `Zip.add`', function () {
describe('Method: `Zip.add`', function() {

it('should return an error on 7z error', function (done) {
it('should return an error on 7z error', function(done) {
add('.tmp/test/addnot.7z', '.tmp/test/nothere', { '???': true })
.catch(function (err) {
.catch(function(err) {
expect(err).to.be.an.instanceof(Error);
done();
});
});

it('should return entries on progress', function (done) {
it('should return entries on progress', function(done) {
add('.tmp/test/add.zip', '*.md')
.progress(function (entries) {
.progress(function(entries) {
expect(entries.length).to.be.at.least(1);
done();
})
.catch(function (err) {
.catch(function(err) {
done();
});
});

it('should accept array as source', function (done) {
it('should accept array as source', function(done) {
var store = [];
add('.tmp/test/add.zip', ['*.md', '*.js'])
.progress(function (entries) {
entries.forEach(function (e) {
.progress(function(entries) {
entries.forEach(function(e) {
store.push(e);
});
})
.done(function () {
.done(function() {
expect(store.length).to.be.at.least(4);
done();
});
Expand Down
26 changes: 13 additions & 13 deletions util/run.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
var os = require('os');
var os = require('os');
var spawn = require('cross-spawn');
var when = require('when');
var path = require('path');
var when = require('when');
var path = require('path');
var utilSwitches = require('./switches');

/**
Expand All @@ -13,8 +13,8 @@ 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) {
return when.promise(function (fulfill, reject, progress) {
module.exports = function(command, switches) {
return when.promise(function(fulfill, reject, progress) {

var macos = (process.platform == "darwin") ? require('macos-release').version : '';
var pathto7z = path.join(__dirname, "..","binaries", macos == '' ? process.platform : process.platform, macos );
Expand All @@ -27,12 +27,12 @@ module.exports = function (command, switches) {
}
// add platform binary to command
var tmpcmd = command.split(' ')[0];
var cmd = path.join(pathto7z,tmpcmd);
var cmd = path.join(pathto7z,tmpcmd);
var args = [ command.split(' ')[1] ];

// Parse and add command (non-switches parameters) to `args`.
var regexpCommands = /"((?:\\.|[^"\\])*)"/g;
var commands = command.match(regexpCommands);
var commands = command.match(regexpCommands);
if (commands) {
commands.forEach(function (c) {
c = c.replace(/\//, path.sep);
Expand All @@ -45,7 +45,7 @@ module.exports = function (command, switches) {
// Special treatment for the output switch because it is exposed as a
// parameter in the API and not as a option. Plus wilcards can be passed.
var regexpOutput = /-o"((?:\\.|[^"\\])*)"/g;
var output = command.match(regexpOutput);
var output = command.match(regexpOutput);
if (output) {
args.pop();
var o = output[0];
Expand All @@ -63,7 +63,7 @@ module.exports = function (command, switches) {
// Remove now double quotes. If present in the spawned process 7-Zip will
// read them as part of the paths (e.g.: create a `"archive.7z"` with
// quotes in the file-name);
args.forEach(function (e, i) {
args.forEach(function(e, i) {
if (typeof e !== 'string') {
return;
}
Expand All @@ -83,7 +83,7 @@ module.exports = function (command, switches) {
cmd: cmd,
args: args,
options: { stdio: 'pipe' } };
console.log('>>', res.cmd, res.args.join(' '), res.options);
console.log('>> ', res.cmd, res.args.join(' '), res.options,' <<');
var run = spawn(res.cmd, res.args, res.options);
run.stdout.on('data', function (data) {
var res = reg.exec(data.toString());
Expand All @@ -92,14 +92,14 @@ module.exports = function (command, switches) {
}
return progress(data.toString());
});
run.stderr.on('data', function (data) {
run.stderr.on('data', function(data) {
//throw errors
err = data.toString();
});
run.on('error', function (err) {
run.on('error', function(err) {
reject(err)
});
run.on('close', function (code) {
run.on('close', function(code) {
if (code === 0) {
return fulfill(args);
}
Expand Down

0 comments on commit 89f8262

Please sign in to comment.