This commit is contained in:
n1474335 2022-07-08 16:23:15 +01:00
commit c02c4a72e4
8 changed files with 175 additions and 1 deletions

View file

@ -325,7 +325,9 @@
"Bzip2 Decompress",
"Bzip2 Compress",
"Tar",
"Untar"
"Untar",
"LZString Compress",
"LZString Decompress"
]
},
{

21
src/core/lib/LZString.mjs Normal file
View file

@ -0,0 +1,21 @@
/**
* lz-string exports.
*
* @author crespyl [peter@crespyl.net]
* @copyright Peter Jacobs 2021
* @license Apache-2.0
*/
import LZString from "lz-string";
export const COMPRESSION_OUTPUT_FORMATS = ["default", "UTF16", "Base64"];
export const COMPRESSION_FUNCTIONS = {
"default": LZString.compress,
"UTF16": LZString.compressToUTF16,
"Base64": LZString.compressToBase64,
};
export const DECOMPRESSION_FUNCTIONS = {
"default": LZString.decompress,
"UTF16": LZString.decompressFromUTF16,
"Base64": LZString.decompressFromBase64,
};

View file

@ -0,0 +1,55 @@
/**
* @author crespyl [peter@crespyl.net]
* @copyright Peter Jacobs 2021
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import {COMPRESSION_OUTPUT_FORMATS, COMPRESSION_FUNCTIONS} from "../lib/LZString.mjs";
/**
* LZString Compress operation
*/
class LZStringCompress extends Operation {
/**
* LZStringCompress constructor
*/
constructor() {
super();
this.name = "LZString Compress";
this.module = "Compression";
this.description = "Compress the input with lz-string.";
this.infoURL = "https://pieroxy.net/blog/pages/lz-string/index.html";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Compression Format",
type: "option",
defaultIndex: 0,
value: COMPRESSION_OUTPUT_FORMATS
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const compress = COMPRESSION_FUNCTIONS[args[0]];
if (compress) {
return compress(input);
} else {
throw new OperationError("Unable to find compression function");
}
}
}
export default LZStringCompress;

View file

@ -0,0 +1,56 @@
/**
* @author crespyl [peter@crespyl.net]
* @copyright Peter Jacobs 2021
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import {COMPRESSION_OUTPUT_FORMATS, DECOMPRESSION_FUNCTIONS} from "../lib/LZString.mjs";
/**
* LZString Decompress operation
*/
class LZStringDecompress extends Operation {
/**
* LZStringDecompress constructor
*/
constructor() {
super();
this.name = "LZString Decompress";
this.module = "Compression";
this.description = "Decompresses data that was compressed with lz-string.";
this.infoURL = "https://pieroxy.net/blog/pages/lz-string/index.html";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Compression Format",
type: "option",
defaultIndex: 0,
value: COMPRESSION_OUTPUT_FORMATS
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const decompress = DECOMPRESSION_FUNCTIONS[args[0]];
if (decompress) {
return decompress(input);
} else {
throw new OperationError("Unable to find decompression function");
}
}
}
export default LZStringDecompress;