-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
var path = require('path'); | ||
var when = require('when'); | ||
var u = { | ||
run: require('../util/run'), | ||
switches : require('../util/switches') | ||
}; | ||
|
||
/** | ||
* Test integrity of archive. | ||
* @promise Test | ||
* @param archive {string} Path to the archive. | ||
* @progress {array} Extracted files and directories. | ||
* @reject {Error} The error as issued by 7-Zip. | ||
*/ | ||
module.exports = function (archive, options) { | ||
return when.promise(function (fulfill, reject, progress) { | ||
|
||
if (options === undefined) { | ||
options = {}; | ||
} | ||
|
||
var opts = u.switches(options); | ||
var command = '7z t ' + archive + ' ' + opts; | ||
u.run(command) | ||
|
||
// 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) { | ||
var entries = []; | ||
data.split('\n').forEach(function (line) { | ||
if (line.substr(0, 12) === 'Testing ') { | ||
entries.push(line.substr(12, line.length).replace(path.sep, '/')); | ||
} | ||
}); | ||
progress(entries); | ||
}) | ||
|
||
.then(function () { | ||
fulfill(); | ||
}) | ||
|
||
.catch(function (err) { | ||
reject(err); | ||
}); | ||
|
||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*global describe, it, afterEach */ | ||
var expect = require('chai').expect; | ||
var fs = require('fs'); | ||
var rimraf = require('rimraf'); | ||
var test = require('../../lib/test'); | ||
|
||
describe('Method: `Zip.test`', function () { | ||
|
||
afterEach(function () { rimraf.sync('.tmp/test'); }); | ||
|
||
it('should return an error on 7z error', function (done) { | ||
test('test/nothere.7z') | ||
.catch(function (err) { | ||
expect(err).to.be.an.instanceof(Error); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return entries on progress', function (done) { | ||
test('test/zip.7z', { r: true }) | ||
.progress(function (entries) { | ||
expect(entries.length).to.be.at.least(1); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); |