Skip to content

Commit

Permalink
Added 'LZ4 Compress' and 'LZ4 Decompress' operations. Closes #1116
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Nov 11, 2022
1 parent ed8bd34 commit 31a7f83
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 1 deletion.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"loglevel": "^1.8.0",
"loglevel-message-prefix": "^3.0.0",
"lz-string": "^1.4.4",
"lz4js": "^0.2.0",
"markdown-it": "^13.0.1",
"moment": "^2.29.3",
"moment-timezone": "^0.5.34",
Expand Down
4 changes: 3 additions & 1 deletion src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@
"LZString Decompress",
"LZString Compress",
"LZMA Decompress",
"LZMA Compress"
"LZMA Compress",
"LZ4 Decompress",
"LZ4 Compress"
]
},
{
Expand Down
43 changes: 43 additions & 0 deletions src/core/operations/LZ4Compress.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2022
* @license Apache-2.0
*/

import Operation from "../Operation.mjs";
import lz4 from "lz4js";

/**
* LZ4 Compress operation
*/
class LZ4Compress extends Operation {

/**
* LZ4Compress constructor
*/
constructor() {
super();

this.name = "LZ4 Compress";
this.module = "Compression";
this.description = "LZ4 is a lossless data compression algorithm that is focused on compression and decompression speed. It belongs to the LZ77 family of byte-oriented compression schemes.";
this.infoURL = "https://wikipedia.org/wiki/LZ4_(compression_algorithm)";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [];
}

/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
const inBuf = new Uint8Array(input);
const compressed = lz4.compress(inBuf);
return compressed.buffer;
}

}

export default LZ4Compress;
43 changes: 43 additions & 0 deletions src/core/operations/LZ4Decompress.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2022
* @license Apache-2.0
*/

import Operation from "../Operation.mjs";
import lz4 from "lz4js";

/**
* LZ4 Decompress operation
*/
class LZ4Decompress extends Operation {

/**
* LZ4Decompress constructor
*/
constructor() {
super();

this.name = "LZ4 Decompress";
this.module = "Compression";
this.description = "LZ4 is a lossless data compression algorithm that is focused on compression and decompression speed. It belongs to the LZ77 family of byte-oriented compression schemes.";
this.infoURL = "https://wikipedia.org/wiki/LZ4_(compression_algorithm)";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [];
}

/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
const inBuf = new Uint8Array(input);
const decompressed = lz4.decompress(inBuf);
return decompressed.buffer;
}

}

export default LZ4Decompress;
30 changes: 30 additions & 0 deletions tests/operations/tests/Compress.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,34 @@ TestRegister.addTests([
}
],
},
{
name: "LZ4 Compress",
input: "The cat sat on the mat.",
expectedOutput: "04224d184070df170000805468652063617420736174206f6e20746865206d61742e00000000",
recipeConfig: [
{
"op": "LZ4 Compress",
"args": []
},
{
"op": "To Hex",
"args": ["None", 0]
}
],
},
{
name: "LZ4 Decompress",
input: "04224d184070df170000805468652063617420736174206f6e20746865206d61742e00000000",
expectedOutput: "The cat sat on the mat.",
recipeConfig: [
{
"op": "From Hex",
"args": ["None"]
},
{
"op": "LZ4 Decompress",
"args": []
}
],
},
]);

0 comments on commit 31a7f83

Please sign in to comment.