Skip to content

Commit

Permalink
add unzip to files
Browse files Browse the repository at this point in the history
Signed-off-by: si458 <simonsmith5521@gmail.com>
  • Loading branch information
si458 committed Mar 2, 2024
1 parent 0e055ef commit 9241c43
Show file tree
Hide file tree
Showing 3 changed files with 1,911 additions and 1,823 deletions.
26 changes: 22 additions & 4 deletions agents/meshcore.js
Expand Up @@ -3438,6 +3438,24 @@ function onTunnelData(data)
this.zip.on('progress', require('events').moderated(function (name, p) { this.xws.write(Buffer.from(JSON.stringify({ action: 'dialogmessage', msg: 'zippingFile', file: ((process.platform == 'win32') ? (name.split('/').join('\\')) : name), progress: p }))); }, 1000));
this.zip.pipe(out);
break;
case 'unzip':
if (this.unzip != null) return; // Unzip operating is currently running, exit now.
this.unzip = require('zip-reader').read(cmd.input);
this.unzip._dest = cmd.dest;
this.unzip.xws = this;
this.unzip.then(function (zipped) {
this.xws.write(Buffer.from(JSON.stringify({ action: 'dialogmessage', msg: 'unzipping' })));
zipped.xws = this.xws;
zipped.extractAll(this._dest).then(function () { // finished extracting
zipped.xws.write(Buffer.from(JSON.stringify({ action: 'dialogmessage', msg: null })));
zipped.xws.write(Buffer.from(JSON.stringify({ action: 'refresh' })));
delete zipped.xws.unzip;
}, function (e) { // error extracting
zipped.xws.write(Buffer.from(JSON.stringify({ action: 'dialogmessage', msg: 'unziperror', error: e })));
delete zipped.xws.unzip;
});
}, function (e) { this.xws.write(Buffer.from(JSON.stringify({ action: 'dialogmessage', msg: 'unziperror', error: e }))); delete this.xws.unzip });
break;
case 'cancel':
// Cancel zip operation if present
try { this.zipcancel = true; this.zip.cancel(function () { }); } catch (ex) { }
Expand Down Expand Up @@ -4247,12 +4265,12 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
break;
case 'unzip':
if (args['_'].length == 0) {
response = "Proper usage: unzip input, destination"; // Display usage
response = "Proper usage: unzip input,destination"; // Display usage
} else {
var p = args['_'].join(' ').split(',');
if (p.length != 2) { response = "Proper usage: unzip input, destination"; break; } // Display usage
var prom = require('zip-reader').read(p[0]);
prom._dest = p[1];
if (p.length != 2) { response = "Proper usage: unzip input,destination"; break; } // Display usage
var prom = require('zip-reader').read(p[0].trim());
prom._dest = p[1].trim();
prom.self = this;
prom.sessionid = sessionid;
prom.then(function (zipped) {
Expand Down

0 comments on commit 9241c43

Please sign in to comment.