Skip to content

Commit

Permalink
revert to repo https://github.com/redx25/node-7z the last travis-ci p…
Browse files Browse the repository at this point in the history
…roject that actaually pass test builds
  • Loading branch information
TheTechsTech committed Feb 6, 2018
1 parent 16512d6 commit d035367
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 166 deletions.
32 changes: 16 additions & 16 deletions lib/add.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
files: require('../util/files'),
run: require('../util/run'),
switches: require('../util/switches')
var u = {
files : require('../util/files'),
run : require('../util/run'),
switches: require('../util/switches'),
};

/**
Expand All @@ -17,38 +17,38 @@ var u = {
* @progress {array} Listed files and directories.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, files, options) {
return when.promise(function(resolve, reject, progress) {
module.exports = function (archive, files, options) {
return when.promise(function (resolve, reject, progress) {

// Convert array of files into a string if needed.
files = u.files(files);
var command = '7za a "' + archive + '" ' + files;

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

// Start the command
u.run(command, 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) {
if (line.substr(0, 13) === 'Compressing ') {
entries.push(line.substr(13, line.length).replace(path.sep, '/'));
data.split('\n').forEach(function (line) {
if (line.substr(0, 1) === '+') {
entries.push(line.substr(2, line.length).replace(path.sep, '/'));
}
});
return progress(entries);
})

// When all is done resolve the Promise.
.then(function(args) {
.then(function (args) {
return resolve(args);
})
.done(function(args) {
console.log(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
18 changes: 8 additions & 10 deletions lib/delete.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
var when = require('when');
var u = {
files: require('../util/files'),
run: require('../util/run'),
switches: require('../util/switches')
var u = {
files : require('../util/files'),
run : require('../util/run'),
switches: require('../util/switches'),
};

/**
Expand All @@ -15,14 +15,14 @@ var u = {
* @resolve {array} Arguments passed to the child-process.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, files, options) {
return when.promise(function(resolve, reject) {
module.exports = function (archive, files, 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 = '7za d "' + archive + '" ' + files;
var command = '7z d "' + archive + '" ' + files;

// Start the command
u.run(command, options)
Expand All @@ -31,9 +31,7 @@ module.exports = function(archive, files, options) {
.then(function (args) {
return resolve(args);
})
.done(function (args) {
console.log(args);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
return reject(err);
Expand Down
33 changes: 11 additions & 22 deletions lib/extract.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
var u = {
run : require('../util/run'),
switches: require('../util/switches')
};

Expand All @@ -16,46 +16,35 @@ var u = {
* @progress {array} Extracted files and directories.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, dest, options) {
return when.promise(function(resolve, reject, progress) {
module.exports = function (archive, dest, options) {
return when.promise(function (resolve, reject, progress) {

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

// Start the command
u.run(command, 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.
// 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'))
// ? true
// : false;
// if (isUnsupportedMethod) {
// return reject(new Error('Unsupported Method'))
//}

data.split('\n').forEach(function (line) {
if (line.substr(0, 12) === 'Extracting ') {
entries.push(line.substr(12, line.length).replace(path.sep, '/'));
if (line.substr(0, 1) === '-') {
entries.push(line.substr(2, line.length).replace(path.sep, '/'));
}
});
return progress(entries);
})

// When all is done resolve the Promise.
.then(function(args) {
.then(function (args) {
return resolve(args);
})
.done(function(args) {
console.log(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
36 changes: 12 additions & 24 deletions lib/extractFull.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
var u = {
run : require('../util/run'),
switches: require('../util/switches')
};

Expand All @@ -16,47 +16,35 @@ var u = {
* @progress {array} Extracted files and directories.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, dest, options) {
return when.promise(function(resolve, reject, progress) {
module.exports = function (archive, dest, options) {
return when.promise(function (resolve, reject, progress) {

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

// Start the command
u.run(command, 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.
// Also check if a file is extracted using an Unsupported Method of 7-Zip.
.progress(function(data) {

// var entries = [];
// var isUnsupportedMethod = (data.search('Unsupported Method'))
// ? true
// : false;
// if (isUnsupportedMethod) {
// console.log(new Error('Unsupported Method'));
// }

.progress(function (data) {
var entries = [];
data.split('\n').forEach(function(line) {
if (line.substr(0, 12) === 'Extracting ') {
entries.push(line.substr(12, line.length).replace(path.sep, '/'));
data.split('\n').forEach(function (line) {
if (line.substr(0, 1) === '-') {
entries.push(line.substr(2, line.length).replace(path.sep, '/'));
}
});
return progress(entries);
})

// When all is done resolve the Promise.
.then(function(args) {
.then(function (args) {
return resolve(args);
})
.done(function(args) {
console.log(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
3 changes: 1 addition & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function makeExecutable(){
FS.chmodSync(filePath, 755);
}
}

var Zip = function () {};

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

module.exports = Zip;
makeExecutable();
makeExecutable()
34 changes: 12 additions & 22 deletions lib/list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
var u = {
run : require('../util/run'),
switches: require('../util/switches')
};

Expand All @@ -15,16 +15,16 @@ var u = {
* @resolve {Object} Tech spec about the archive.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, options) {
return when.promise(function(resolve, reject, progress) {
module.exports = function (archive, options) {
return when.promise(function (resolve, reject, progress) {

var spec = {};
/* jshint maxlen: 130 */
var regex = /(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ([\.DA]+)\s+(\d+)\s*(?:\d+)\s+(\S+?\.\S+)/;
var regex = /(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ([\.D][\.R][\.H][\.S][\.A]) +(\d+) +(\d+)? +(.+)/;
/* jshint maxlen: 80 */

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

var buffer = ""; //Store imcomplete line of a progress data.
// Start the command
Expand All @@ -33,7 +33,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 @@ -43,7 +43,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 All @@ -57,20 +57,12 @@ module.exports = function(archive, options) {
spec.physicalSize = parseInt(line.substr(16, line.length), 10);
} else if (line.substr(0, 15) === 'Headers Size = ') {
spec.headersSize = parseInt(line.substr(15, line.length), 10);
} else if (line.substr(0, 12) === 'Encrypted = ') {
spec.encrypted = line.substr(12, line.length);
} else {
// Parse the stdout to find entries
var res = regex.exec(line);
if (res) {
if (parseInt(res[1])) {
var return_date = new Date(res[1]);
} else {
var return_date = null;
}

var e = {
date: return_date,
date: new Date(res[1]),
attr: res[2],
size: parseInt(res[3], 10),
name: res[5].replace(path.sep, '/')
Expand All @@ -88,14 +80,12 @@ module.exports = function(archive, options) {
})

// When all is done resolve the Promise.
.then(function() {
.then(function () {
return resolve(spec);
})
.done(function(args) {
console.log(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
18 changes: 8 additions & 10 deletions lib/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
var u = {
run : require('../util/run'),
switches: require('../util/switches')
};

Expand All @@ -15,11 +15,11 @@ var u = {
* @progress {array} Extracted files and directories.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, options) {
return when.promise(function(resolve, reject, progress) {
module.exports = function (archive, options) {
return when.promise(function (resolve, reject, progress) {

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

// Start the command
u.run(command, options)
Expand All @@ -30,8 +30,8 @@ module.exports = function(archive, options) {
.progress(function (data) {
var entries = [];
data.split('\n').forEach(function (line) {
if (line.substr(0, 12) === 'Testing ') {
entries.push(line.substr(12, line.length).replace(path.sep, '/'));
if (line.substr(0, 1) === 'T') {
entries.push(line.substr(2, line.length).replace(path.sep, '/'));
}
});
return progress(entries);
Expand All @@ -41,9 +41,7 @@ module.exports = function(archive, options) {
.then(function (args) {
return resolve(args);
})
.done(function(args) {
console.log(args);
})

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

0 comments on commit d035367

Please sign in to comment.