Skip to content

Commit

Permalink
indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mansurt committed Apr 26, 2017
1 parent a46e6bf commit 31ea6a6
Showing 1 changed file with 69 additions and 68 deletions.
137 changes: 69 additions & 68 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,11 +15,12 @@ var u = {
* @resolve {Object} Tech spec about the archive.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function(archive, options, filesRequiredFields) {
return when.promise(function(resolve, reject, progress) {
module.exports = function (archive, options, filesRequiredFields) {
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}) ([\.DA]+)\s+(\d+)\s*(?:\d+)\s+(\S+?\.\S+)/;
/* jshint maxlen: 80 */

// Create a string that can be parsed by `run`.
Expand All @@ -32,88 +33,88 @@ module.exports = function(archive, options, filesRequiredFields) {
// 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
// buffer.
if (buffer.length > 0) {
data = buffer + data;
buffer = "";
}

if (options && options.slt) {
try {
let retval = parseSltOutput(data, filesRequiredFields);
return resolve(retval);
if (buffer.length > 0) {
data = buffer + data;
buffer = "";
}
catch(err) {
return reject(retval);
};
}

data.split('\n').forEach(function(line) {
// Populate the tech specs of the archive that are passed to the
// resolve handler.
if (line.substr(0, 7) === 'Path = ') {
if (isRequiredProperty(filesRequiredFields, 'Path')) {
spec.path = line.substr(7, line.length);
}
} else if (line.substr(0, 7) === 'Type = ') {
if (isRequiredProperty(filesRequiredFields, 'Type')) {
spec.type = line.substr(7, line.length);
}
} else if (line.substr(0, 9) === 'Method = ') {
if (isRequiredProperty(filesRequiredFields, 'Method')) {
spec.method = line.substr(9, line.length);
}
} else if (line.substr(0, 16) === 'Physical Size = ') {
if (isRequiredProperty(filesRequiredFields, 'Physical Size')) {
spec.physicalSize = parseInt(line.substr(16, line.length), 10);
}
} else if (line.substr(0, 15) === 'Headers Size = ') {
if (isRequiredProperty(filesRequiredFields, 'Headers Size')) {
spec.headersSize = parseInt(line.substr(15, line.length), 10);
}
} else if (line.substr(0, 12) === 'Encrypted = ') {
if (isRequiredProperty(filesRequiredFields, 'Encrypted')) {
pec.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;
if (options && options.slt) {
try {
let retval = parseSltOutput(data, filesRequiredFields);
return resolve(retval);
}

var e = {
date: return_date,
attr: res[2],
size: parseInt(res[3], 10),
name: res[5].replace(path.sep, '/')
catch(err) {
return reject(retval);
};

entries.push(e);
}

// Line may be incomplete, Save it to the buffer.
else buffer = line;
data.split('\n').forEach(function (line) {
// Populate the tech specs of the archive that are passed to the
// resolve handler.
if (line.substr(0, 7) === 'Path = ') {
if (isRequiredProperty(filesRequiredFields, 'Path')) {
spec.path = line.substr(7, line.length);
}
} else if (line.substr(0, 7) === 'Type = ') {
if (isRequiredProperty(filesRequiredFields, 'Type')) {
spec.type = line.substr(7, line.length);
}
} else if (line.substr(0, 9) === 'Method = ') {
if (isRequiredProperty(filesRequiredFields, 'Method')) {
spec.method = line.substr(9, line.length);
}
} else if (line.substr(0, 16) === 'Physical Size = ') {
if (isRequiredProperty(filesRequiredFields, 'Physical Size')) {
spec.physicalSize = parseInt(line.substr(16, line.length), 10);
}
} else if (line.substr(0, 15) === 'Headers Size = ') {
if (isRequiredProperty(filesRequiredFields, 'Headers Size')) {
spec.headersSize = parseInt(line.substr(15, line.length), 10);
}
} else if (line.substr(0, 12) === 'Encrypted = ') {
if (isRequiredProperty(filesRequiredFields, 'Encrypted')) {
pec.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,
attr: res[2],
size: parseInt(res[3], 10),
name: res[5].replace(path.sep, '/')
};

entries.push(e);
}

}
});
// Line may be incomplete, Save it to the buffer.
else buffer = line;

}
});
return progress(entries);
})

// 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

0 comments on commit 31ea6a6

Please sign in to comment.