2018-04-02 21:46:55 +02:00
|
|
|
/**
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Operation from "../Operation";
|
|
|
|
import Utils from "../Utils";
|
|
|
|
import unzip from "zlibjs/bin/unzip.min";
|
|
|
|
|
|
|
|
const Zlib = unzip.Zlib;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unzip operation
|
|
|
|
*/
|
|
|
|
class Unzip extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unzip constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Unzip";
|
|
|
|
this.module = "Compression";
|
|
|
|
this.description = "Decompresses data using the PKZIP algorithm and displays it per file, with support for passwords.";
|
|
|
|
this.inputType = "byteArray";
|
2018-04-06 20:11:13 +02:00
|
|
|
this.outputType = "List<File>";
|
|
|
|
this.presentType = "html";
|
2018-04-02 21:46:55 +02:00
|
|
|
this.args = [
|
|
|
|
{
|
|
|
|
name: "Password",
|
|
|
|
type: "binaryString",
|
|
|
|
value: ""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Verify result",
|
|
|
|
type: "boolean",
|
|
|
|
value: false
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {byteArray} input
|
|
|
|
* @param {Object[]} args
|
2018-04-06 20:11:13 +02:00
|
|
|
* @returns {File[]}
|
2018-04-02 21:46:55 +02:00
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
const options = {
|
|
|
|
password: Utils.strToByteArray(args[0]),
|
|
|
|
verify: args[1]
|
|
|
|
},
|
|
|
|
unzip = new Zlib.Unzip(input, options),
|
2018-04-06 20:11:13 +02:00
|
|
|
filenames = unzip.getFilenames();
|
2018-04-02 21:46:55 +02:00
|
|
|
|
2018-04-06 20:11:13 +02:00
|
|
|
return filenames.map(fileName => {
|
2018-04-02 21:46:55 +02:00
|
|
|
const bytes = unzip.decompress(fileName);
|
2018-04-06 20:11:13 +02:00
|
|
|
return new File([bytes], fileName);
|
2018-04-02 21:46:55 +02:00
|
|
|
});
|
2018-04-06 20:11:13 +02:00
|
|
|
}
|
2018-04-02 21:46:55 +02:00
|
|
|
|
2018-04-06 20:11:13 +02:00
|
|
|
/**
|
|
|
|
* Displays the files in HTML for web apps.
|
|
|
|
*
|
|
|
|
* @param {File[]} files
|
|
|
|
* @returns {html}
|
|
|
|
*/
|
|
|
|
async present(files) {
|
|
|
|
return await Utils.displayFilesAsHTML(files);
|
2018-04-02 21:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Unzip;
|