Skip to content

Commit

Permalink
small issues fixes
Browse files Browse the repository at this point in the history
i know it's not a good description
  • Loading branch information
q2s2t committed Mar 22, 2017
1 parent 47f99a6 commit 48013fd
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ before_install:
language: node_js
node_js:
- '6'
- '7'
script: 'npm run coverage'
after_script: 'npm run coveralls'
4 changes: 2 additions & 2 deletions lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = function (archive, files, options) {

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

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

// Start the command
u.run(command, options)
Expand Down
9 changes: 9 additions & 0 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ module.exports = function (archive, dest, 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) {
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, '/'));
Expand Down
10 changes: 10 additions & 0 deletions lib/extractFull.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ module.exports = function (archive, dest, 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) {
return reject(new Error('Unsupported Method'))
}

var entries = [];
data.split('\n').forEach(function (line) {
if (line.substr(0, 12) === 'Extracting ') {
Expand Down
8 changes: 7 additions & 1 deletion lib/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ module.exports = function (archive, options) {
// 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: new Date(res[1]),
date: return_date,
attr: res[2],
size: parseInt(res[3], 10),
name: res[5].replace(path.sep, '/')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A Node.js wrapper for 7-Zip",
"main": "lib/index.js",
"scripts": {
"test": "mocha",
"test": "mocha --debug",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha --dir .tmp/coverage",
"coveralls": "npm install coveralls && cat .tmp/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
},
Expand Down
5 changes: 4 additions & 1 deletion test/lib/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ describe('Method: `Zip.add`', function () {
.progress(function (entries) {
expect(entries.length).to.be.at.least(1);
done();
})
.catch(function (err) {
done();
});
});

Expand All @@ -35,7 +38,7 @@ describe('Method: `Zip.add`', function () {
done();
});
});

it('should accept a path', function (done) {
add('.tmp/test/add.zip', '*.md', {
path: '/usr/local/bin/7z'
Expand Down
13 changes: 13 additions & 0 deletions test/lib/extract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,17 @@ describe('Method: `Zip.extract`', function () {
});
});

it('should return a countable list of files on progress', function (done) {
var filesNumber = 0
extract('test/zip.7z', '.tmp/test2')
.progress(function (entries) {
console.log(entries);
filesNumber += entries.length;
})
.then(function () {
expect(filesNumber).to.be.equal(6);
done();
});
});

});
13 changes: 13 additions & 0 deletions test/util/path.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*global describe, it */
'use strict';
var expect = require('chai').expect;
var exec = require('child_process').execSync;
var path = require('../../util/path');

describe('Utility: `path`', function () {

it('should return deflaut flags with no args', function () {
var pathInSystem = exec('which 7z').toString();
});

});
8 changes: 4 additions & 4 deletions test/util/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe('Utility: `run`', function () {
});

it('should return an error on when 7z gets one', function (done) {
run('7z "???"').catch(function (err) {
run('7za "???"').catch(function (err) {
expect(err.message).to.eql('Incorrect command line');
done();
});
});

it('should return an stdout on progress', function (done) {
run('7z', { h: true })
run('7za', { h: true })
.progress(function (data) {
expect(data).to.be.a('string');
})
Expand All @@ -31,7 +31,7 @@ describe('Utility: `run`', function () {
});

it('should correctly parse complex commands', function (done) {
run('7z a ".tmp/test/archive.7z" "*.exe" "*.dll"', {
run('7za a ".tmp/test/archive.7z" "*.exe" "*.dll"', {
m0: '=BCJ',
m1: '=LZMA:d=21'
})
Expand All @@ -49,7 +49,7 @@ describe('Utility: `run`', function () {
});

it('should correctly parse complex commands with spaces', function (done) {
run('7z a ".tmp/Folder A/Folder B\\archive.7z" "*.exe" "*.dll"', {
run('7za a ".tmp/Folder A/Folder B\\archive.7z" "*.exe" "*.dll"', {
m0: '=BCJ',
m1: '=LZMA:d=21',
p : 'My mhjls/\\c $^é5°',
Expand Down
1 change: 1 addition & 0 deletions test/zip/file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
1 change: 1 addition & 0 deletions test/zip/file2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
1 change: 1 addition & 0 deletions test/zip/file3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
1 change: 1 addition & 0 deletions test/zip/folder/file0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
18 changes: 18 additions & 0 deletions util/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

module.exports = function (options) {

// Create a string that can be parsed by `run`.
try {

if (options.path) {
return options.path;
} else {
return '7z';
}

} catch (e) {
throw new Error('Path to the 7-Zip bin not found');
}

};
2 changes: 1 addition & 1 deletion util/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = function (command, switches) {
cmd: cmd,
args: args,
options: { stdio: 'pipe' } };
// console.log('>>', res.cmd, res.args.join(' '));

var run = spawn(res.cmd, res.args, res.options);
run.stdout.on('data', function (data) {
var res = reg.exec(data.toString());
Expand Down
4 changes: 3 additions & 1 deletion util/switches.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ module.exports = function (switches) {

// Special treatment for wilcards
if (s === 'wildcards') {
a.unshift(switches.wildcards);
switches.wildcards.forEach(function (wildvalue, index) {
a.unshift(wildvalue);
});
}

// Allow raw switches to be added to the command, repeating switches like
Expand Down

0 comments on commit 48013fd

Please sign in to comment.