feature(operation) add support of unpacking bzip2 archives: .bz2, .tar.bz2, .tbz2

This commit is contained in:
coderaiser 2017-04-24 14:06:52 +03:00
parent 4f61036847
commit 9641415a00
5 changed files with 59 additions and 12 deletions

View file

@ -12,6 +12,7 @@
[DEEPWORD]: https://github.com/cloudcmd/deepword "Editor based on Monaco"
[EDWARD_KEYS]: https://github.com/cloudcmd/edward/#hot-keys "Edward Hot keys"
[TERMUX]: https://termux.com "Termux"
[INLY]: https://github.com/coderaiser/node-inly "Extract archive"
**Cloud Commander** is an orthodox web file manager with console and editor. Will help you manage the server and work with files, directories and programs in browser from any computer, mobile or tablet.
![Cloud Commander](/img/logo/cloudcmd.png "Cloud Commander")
@ -29,6 +30,8 @@ Benefits
- **3 built-in editors** with support of **syntax highlighting**: [Dword][DWORD], [Edward][EDWARD] and [Deepword][DEEPWORD].
- [Console](https://github.com/cloudcmd/console "Console") with support of default OS command line.
- Written in **JavaScript/Node.js**.
- Built-in archives pack: **zip** and **tar.gz**.
- Built-in archives extract: **zip**, **tar**, **gz**, **bz2**, **.tar.gz** and **.tar.bz2** (with help of [inly][INLY]).
Install
---------------

View file

@ -14,7 +14,8 @@ CloudCmd.Operation = OperationProto;
const currify = require('currify/legacy');
const exec = require('execon');
const RESTful = require('../dom/rest');
const RESTful = require('../../dom/rest');
const removeExtension = require('./remove-extension');
function OperationProto(operation, data) {
const Name = 'Operation';
@ -272,8 +273,7 @@ function OperationProto(operation, data) {
};
this.extract = () => {
const isZip = config('packer') === 'zip';
twopack('extract', isZip ? 'zip' : 'tar');
twopack('extract');
};
/**
@ -456,13 +456,6 @@ function OperationProto(operation, data) {
}
}
function getTypeReg(type) {
if (type === 'zip')
return /\.zip$/;
return /\.tar\.gz$/;
}
function checkEmpty(name, operation) {
if (!operation)
throw Error(name + ' could not be empty!');
@ -493,7 +486,7 @@ function OperationProto(operation, data) {
to: dirPath
};
currentName = currentName.replace(getTypeReg(type), '');
currentName = removeExtension(currentName);
break;

View file

@ -0,0 +1,20 @@
'use strict';
const {getExt} = require('../../../common/util');
module.exports = (name) => {
const ext = getExtension(name);
return name.replace(ext, '');
};
function getExtension(name) {
if (/\.tar\.gz$/.test(name))
return '.tar.gz';
if (/\.tar\.bz2$/.test(name))
return '.tar.bz2';
return getExt(name);
}

View file

@ -0,0 +1,31 @@
'use strict';
const test = require('tape');
const dir = '../../../../client/modules/operation';
const removeExtension = require(`${dir}/remove-extension`);
test('cloudcmd: client: modules: operation: removeExtension: .tar.gz', (t) => {
const name = 'hello';
const fullName = `${name}.tar.gz`;
t.equal(removeExtension(fullName), name, 'should remove .tar.gz');
t.end();
});
test('cloudcmd: client: modules: operation: removeExtension: .tar.bz2', (t) => {
const name = 'hello';
const fullName = `${name}.tar.bz2`;
t.equal(removeExtension(fullName), name, 'should remove .tar.bz2');
t.end();
});
test('cloudcmd: client: modules: operation: removeExtension: .bz2', (t) => {
const name = 'hello';
const fullName = `${name}.bz2`;
t.equal(removeExtension(fullName), name, 'should remove .bz2');
t.end();
});

View file

@ -50,7 +50,7 @@ module.exports = {
[modules + '/config']: `${dirModules}/config.js`,
[modules + '/contact']: `${dirModules}/contact.js`,
[modules + '/upload']: `${dirModules}/upload.js`,
[modules + '/operation']: `${dirModules}/operation.js`,
[modules + '/operation']: `${dirModules}/operation/index.js`,
[modules + '/konsole']: `${dirModules}/konsole.js`,
[modules + '/terminal']: `${dirModules}/terminal.js`,
[modules + '/cloud']: `${dirModules}/cloud.js`,