Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mansurt committed Apr 26, 2017
1 parent d30b2bf commit 952ee16
Showing 1 changed file with 13 additions and 53 deletions.
66 changes: 13 additions & 53 deletions lib/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ var u = {
switches: require('../util/switches')
};

const PROPERTY_DELIM = ' = ';
const META_BEGINNING = '--';
const META_DATA_DELIM = '----------';
const FILE_DELIM = '';

/**
* List contents of archive.
* @promise List
Expand Down Expand Up @@ -78,7 +83,7 @@ module.exports = function (archive, options, filesRequiredFields) {
}
} else if (line.substr(0, 12) === 'Encrypted = ') {
if (isRequiredProperty(filesRequiredFields, 'Encrypted')) {
pec.encrypted = line.substr(12, line.length);
spec.encrypted = line.substr(12, line.length);
}
} else {
// Parse the stdout to find entries
Expand Down Expand Up @@ -125,93 +130,48 @@ function isRequiredProperty(requiredPropertyArr, name) {
return !requiredPropertyArr || (requiredPropertyArr.indexOf(name) >= 0);
}

const propertyDelim = ' = ';

function parseProperty(data, propObj, requiredPropertyArr) {
let pos = data.indexOf(propertyDelim);
let pos = data.indexOf(PROPERTY_DELIM);

if (pos === -1) {
return;
}

let key = data.substring(0, pos);
let value = data.substring(pos + propertyDelim.length, data.length);
let value = data.substring(pos + PROPERTY_DELIM.length, data.length);
if (isRequiredProperty(requiredPropertyArr, key)) {
propObj[key] = value;
}
};

const metaBegining = '--';
const metaDataDelim = '----------';
const fileDelim = '';

/*
* Output of 7z with slt option contains 7z version. '--', metaData, '----------', and fileData for each archived file separated by an empty line.
* Both metaData and fileData are set of <key> = <value> separated by a new line
* Example:
*
* 7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
* p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,4 CPUs)
*
* Listing archive: example.7z
*
* --
* Path = example.7z
* Type = 7z
* Method = LZMA
* Solid = +
* Blocks = 1
* Physical Size = 24948
* Headers Size = 178
* ----------
* Path = test.7z
* Size = 304
* Packed Size = 24770
* Modified = 2017-03-20 13:10:16
* Attributes = ....A
* CRC = 55F6B511
* Encrypted = -
* Method = LZMA:16
* Block = 0
* Path = test.zip
* Size = 24305
* Packed Size =
* Modified = 2016-03-06 13:55:38
* Attributes = ....A
* CRC = F891B5C2
* Encrypted = -
* Method = LZMA:16
* Block = 0
*/
function parseSltOutput(data, filesRequiredFields) {
let lines = data.split('\n');
let retval = {metaData: {}, files: []};

let i = lines.indexOf(metaBegining);
let i = lines.indexOf(META_BEGINNING);
if (i < 0) {
throw new Error('Invalid data ' + JSON.stringify(data));
}

for (i = i + 1; i < lines.length && lines[i] !== metaDataDelim; i++) {
for (i = i + 1; i < lines.length && lines[i] !== META_DATA_DELIM; ++i) {
if (lines[i].length === 0) {
continue;
}

parseProperty(lines[i], retval.metaData, null /* shouldn't filter metaData properties */);
}

i++; //for metaDataDelim

//parse files
for (; i < lines.length; i++) {
if (!lines[i].length) {
for (i = i + 1; i < lines.length; ++i) {
if (lines[i].length === 0) {
continue;
}
let file = {};
for (; i < lines.length && lines[i] !== fileDelim; i++) {
for (; i < lines.length && lines[i] !== FILE_DELIM; ++i) {
parseProperty(lines[i], file, filesRequiredFields);
}

Expand Down

0 comments on commit 952ee16

Please sign in to comment.