Lots of progress on packet writing, reading, etc.

* Bug fixes
* Create packet archive
This commit is contained in:
Bryan Ashby
2020-04-27 20:55:41 -06:00
parent 8a81b34ed0
commit 2b7d810c77
2 changed files with 160 additions and 46 deletions

View File

@@ -204,23 +204,37 @@ module.exports = class ArchiveUtil {
});
}
compressTo(archType, archivePath, files, cb) {
compressTo(archType, archivePath, files, workDir, cb) {
const archiver = this.getArchiver(archType, paths.extname(archivePath));
if(!archiver) {
return cb(Errors.Invalid(`Unknown archive type: ${archType}`));
}
if (!cb && _.isFunction(workDir)) {
cb = workDir;
workDir = null;
}
const fmtObj = {
archivePath : archivePath,
fileList : files.join(' '), // :TODO: probably need same hack as extractTo here!
};
const args = archiver.compress.args.map( arg => stringFormat(arg, fmtObj) );
// :TODO: DRY with extractTo()
const args = archiver.compress.args.map( arg => {
return '{fileList}' === arg ? arg : stringFormat(arg, fmtObj);
});
const fileListPos = args.indexOf('{fileList}');
if(fileListPos > -1) {
// replace {fileList} with 0:n sep file list arguments
args.splice.apply(args, [fileListPos, 1].concat(files));
}
let proc;
try {
proc = pty.spawn(archiver.compress.cmd, args, this.getPtyOpts());
proc = pty.spawn(archiver.compress.cmd, args, this.getPtyOpts(workDir));
} catch(e) {
return cb(Errors.ExternalProcess(
`Error spawning archiver process "${archiver.compress.cmd}" with args "${args.join(' ')}": ${e.message}`)
@@ -332,15 +346,15 @@ module.exports = class ArchiveUtil {
});
}
getPtyOpts(extractPath) {
getPtyOpts(cwd) {
const opts = {
name : 'enigma-archiver',
cols : 80,
rows : 24,
env : process.env,
};
if(extractPath) {
opts.cwd = extractPath;
if(cwd) {
opts.cwd = cwd;
}
// :TODO: set cwd to supplied temp path if not sepcific extract
return opts;