* Allow alternate matching group order for archive short/long desc
* max short/long desc file input byte size (ignore files larger than N) * Add Arj support via 'arj'
This commit is contained in:
parent
9525afddd3
commit
6f1015305b
|
@ -256,18 +256,16 @@ module.exports = class ArchiveUtil {
|
||||||
if(exitCode) {
|
if(exitCode) {
|
||||||
return cb(new Error(`List failed with exit code: ${exitCode}`));
|
return cb(new Error(`List failed with exit code: ${exitCode}`));
|
||||||
}
|
}
|
||||||
//if(err) {
|
|
||||||
// return cb(err);
|
const entryGroupOrder = archiver.list.entryGroupOrder || { byteSize : 1, fileName : 2 };
|
||||||
// }
|
|
||||||
|
|
||||||
const entries = [];
|
const entries = [];
|
||||||
const entryMatchRe = new RegExp(archiver.list.entryMatch, 'gm');
|
const entryMatchRe = new RegExp(archiver.list.entryMatch, 'gm');
|
||||||
let m;
|
let m;
|
||||||
while((m = entryMatchRe.exec(output))) {
|
while((m = entryMatchRe.exec(output))) {
|
||||||
// :TODO: allow alternate ordering!!!
|
|
||||||
entries.push({
|
entries.push({
|
||||||
byteSize : parseInt(m[1]),
|
byteSize : parseInt(m[entryGroupOrder.byteSize]),
|
||||||
fileName : m[2],
|
fileName : m[entryGroupOrder.fileName],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,7 @@ function getDefaultConfig() {
|
||||||
},
|
},
|
||||||
decompress : {
|
decompress : {
|
||||||
cmd : '7za',
|
cmd : '7za',
|
||||||
args : [ 'e', '-o{extractPath}', '{archivePath}' ]
|
args : [ 'e', '-o{extractPath}', '{archivePath}' ] // :TODO: should be 'x'?
|
||||||
},
|
},
|
||||||
list : {
|
list : {
|
||||||
cmd : '7za',
|
cmd : '7za',
|
||||||
|
@ -279,6 +279,30 @@ function getDefaultConfig() {
|
||||||
cmd : 'lha',
|
cmd : 'lha',
|
||||||
args : [ '-ew={extractPath}', '{archivePath}', '{fileList}' ]
|
args : [ '-ew={extractPath}', '{archivePath}', '{fileList}' ]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Arj : {
|
||||||
|
//
|
||||||
|
// 'arj' command can be obtained from:
|
||||||
|
// * apt-get: arj
|
||||||
|
//
|
||||||
|
decompress : {
|
||||||
|
cmd : 'arj',
|
||||||
|
args : [ 'x', '{archivePath}', '{extractPath}' ],
|
||||||
|
},
|
||||||
|
list : {
|
||||||
|
cmd : 'arj',
|
||||||
|
args : [ 'l', '{archivePath}' ],
|
||||||
|
entryMatch : '^([^\\s]+)\\s+([0-9]+)\\s+[0-9]+\\s[0-9\\.]+\\s+[0-9]{2}\\-[0-9]{2}\\-[0-9]{2}\\s[0-9]{2}\\:[0-9]{2}\\:[0-9]{2}\\s+(?:[^\\r\\n]+)$',
|
||||||
|
entryGroupOrder : { // defaults to { byteSize : 1, fileName : 2 }
|
||||||
|
fileName : 1,
|
||||||
|
byteSize : 2,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
extract : {
|
||||||
|
cmd : 'arj',
|
||||||
|
args : [ 'e', '{archivePath}', '{extractPath}', '{fileList}' ],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -305,7 +329,7 @@ function getDefaultConfig() {
|
||||||
sig : '60ea',
|
sig : '60ea',
|
||||||
offset : 0,
|
offset : 0,
|
||||||
exts : [ 'arj' ],
|
exts : [ 'arj' ],
|
||||||
handler : '7Zip',
|
handler : 'Arj',
|
||||||
desc : 'ARJ Archive',
|
desc : 'ARJ Archive',
|
||||||
},
|
},
|
||||||
rar : {
|
rar : {
|
||||||
|
@ -428,15 +452,18 @@ function getDefaultConfig() {
|
||||||
// areas with an explicit |storageDir| will be stored relative to |areaStoragePrefix|:
|
// areas with an explicit |storageDir| will be stored relative to |areaStoragePrefix|:
|
||||||
areaStoragePrefix : paths.join(__dirname, './../file_base/'),
|
areaStoragePrefix : paths.join(__dirname, './../file_base/'),
|
||||||
|
|
||||||
|
maxDescFileByteSize : 471859, // ~1/4 MB
|
||||||
|
maxDescLongFileByteSize : 524288, // 1/2 MB
|
||||||
|
|
||||||
fileNamePatterns: {
|
fileNamePatterns: {
|
||||||
// These are NOT case sensitive
|
// These are NOT case sensitive
|
||||||
// FILE_ID.DIZ - https://en.wikipedia.org/wiki/FILE_ID.DIZ
|
// FILE_ID.DIZ - https://en.wikipedia.org/wiki/FILE_ID.DIZ
|
||||||
shortDesc : [
|
desc : [
|
||||||
'^FILE_ID\.DIZ$', '^DESC\.SDI$', '^DESCRIPT\.ION$', '^FILE\.DES$', '$FILE\.SDI$', '^DISK\.ID$'
|
'^FILE_ID\.DIZ$', '^DESC\.SDI$', '^DESCRIPT\.ION$', '^FILE\.DES$', '$FILE\.SDI$', '^DISK\.ID$'
|
||||||
],
|
],
|
||||||
|
|
||||||
// common README filename - https://en.wikipedia.org/wiki/README
|
// common README filename - https://en.wikipedia.org/wiki/README
|
||||||
longDesc : [
|
descLong : [
|
||||||
'^.*\.NFO$', '^README\.1ST$', '^README\.TXT$', '^READ\.ME$', '^README$', '^README\.md$'
|
'^.*\.NFO$', '^README\.1ST$', '^README\.TXT$', '^READ\.ME$', '^README$', '^README\.md$'
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -280,7 +280,7 @@ function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, c
|
||||||
const extractList = [];
|
const extractList = [];
|
||||||
|
|
||||||
const shortDescFile = entries.find( e => {
|
const shortDescFile = entries.find( e => {
|
||||||
return Config.fileBase.fileNamePatterns.shortDesc.find( pat => new RegExp(pat, 'i').test(e.fileName) );
|
return Config.fileBase.fileNamePatterns.desc.find( pat => new RegExp(pat, 'i').test(e.fileName) );
|
||||||
});
|
});
|
||||||
|
|
||||||
if(shortDescFile) {
|
if(shortDescFile) {
|
||||||
|
@ -288,7 +288,7 @@ function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, c
|
||||||
}
|
}
|
||||||
|
|
||||||
const longDescFile = entries.find( e => {
|
const longDescFile = entries.find( e => {
|
||||||
return Config.fileBase.fileNamePatterns.longDesc.find( pat => new RegExp(pat, 'i').test(e.fileName) );
|
return Config.fileBase.fileNamePatterns.descLong.find( pat => new RegExp(pat, 'i').test(e.fileName) );
|
||||||
});
|
});
|
||||||
|
|
||||||
if(longDescFile) {
|
if(longDescFile) {
|
||||||
|
@ -319,13 +319,25 @@ function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, c
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function readDescFiles(descFiles, callback) {
|
function readDescFiles(descFiles, callback) {
|
||||||
// :TODO: we shoudl probably omit files that are too large
|
|
||||||
async.each(Object.keys(descFiles), (descType, next) => {
|
async.each(Object.keys(descFiles), (descType, next) => {
|
||||||
const path = descFiles[descType];
|
const path = descFiles[descType];
|
||||||
if(!path) {
|
if(!path) {
|
||||||
return next(null);
|
return next(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs.stat(path, (err, stats) => {
|
||||||
|
if(err) {
|
||||||
|
return next(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip entries that are too large
|
||||||
|
const maxFileSizeKey = `max${_.upperFirst(descType)}FileByteSize`;
|
||||||
|
|
||||||
|
if(Config.fileBase[maxFileSizeKey] && stats.size > Config.fileBase[maxFileSizeKey]) {
|
||||||
|
Log.debug( { byteSize : stats.size, maxByteSize : Config.fileBase[maxFileSizeKey] }, `Skipping "${descType}"; Too large` );
|
||||||
|
return next(null);
|
||||||
|
}
|
||||||
|
|
||||||
fs.readFile(path, (err, data) => {
|
fs.readFile(path, (err, data) => {
|
||||||
if(err || !data) {
|
if(err || !data) {
|
||||||
return next(null);
|
return next(null);
|
||||||
|
@ -338,6 +350,7 @@ function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, c
|
||||||
fileEntry[descType] = iconv.decode(sliceAtSauceMarker(data, 0x1a), 'cp437');
|
fileEntry[descType] = iconv.decode(sliceAtSauceMarker(data, 0x1a), 'cp437');
|
||||||
return next(null);
|
return next(null);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}, () => {
|
}, () => {
|
||||||
// cleanup but don't wait
|
// cleanup but don't wait
|
||||||
temptmp.cleanup( paths => {
|
temptmp.cleanup( paths => {
|
||||||
|
|
|
@ -371,6 +371,10 @@ function cleanControlCodes(input, options) {
|
||||||
|
|
||||||
function createCleanAnsi(input, options, cb) {
|
function createCleanAnsi(input, options, cb) {
|
||||||
|
|
||||||
|
if(!input) {
|
||||||
|
return cb('');
|
||||||
|
}
|
||||||
|
|
||||||
options.width = options.width || 80;
|
options.width = options.width || 80;
|
||||||
options.height = options.height || 25;
|
options.height = options.height || 25;
|
||||||
|
|
||||||
|
|
1
main.js
1
main.js
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/* jslint node: true */
|
/* jslint node: true */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
"temptmp" : "^1.0.0"
|
"temptmp" : "^1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"lodash-migrate": "^0.3.16"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.9.2"
|
"node": ">=6.9.2"
|
||||||
|
|
Loading…
Reference in New Issue