Skip to content

Commit 31a7f83

Browse files
committed
Added 'LZ4 Compress' and 'LZ4 Decompress' operations. Closes #1116
1 parent ed8bd34 commit 31a7f83

File tree

6 files changed

+131
-1
lines changed

6 files changed

+131
-1
lines changed

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
"loglevel": "^1.8.0",
135135
"loglevel-message-prefix": "^3.0.0",
136136
"lz-string": "^1.4.4",
137+
"lz4js": "^0.2.0",
137138
"markdown-it": "^13.0.1",
138139
"moment": "^2.29.3",
139140
"moment-timezone": "^0.5.34",

src/core/config/Categories.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@
333333
"LZString Decompress",
334334
"LZString Compress",
335335
"LZMA Decompress",
336-
"LZMA Compress"
336+
"LZMA Compress",
337+
"LZ4 Decompress",
338+
"LZ4 Compress"
337339
]
338340
},
339341
{

src/core/operations/LZ4Compress.mjs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @author n1474335 [[email protected]]
3+
* @copyright Crown Copyright 2022
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
import lz4 from "lz4js";
9+
10+
/**
11+
* LZ4 Compress operation
12+
*/
13+
class LZ4Compress extends Operation {
14+
15+
/**
16+
* LZ4Compress constructor
17+
*/
18+
constructor() {
19+
super();
20+
21+
this.name = "LZ4 Compress";
22+
this.module = "Compression";
23+
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.";
24+
this.infoURL = "https://wikipedia.org/wiki/LZ4_(compression_algorithm)";
25+
this.inputType = "ArrayBuffer";
26+
this.outputType = "ArrayBuffer";
27+
this.args = [];
28+
}
29+
30+
/**
31+
* @param {ArrayBuffer} input
32+
* @param {Object[]} args
33+
* @returns {ArrayBuffer}
34+
*/
35+
run(input, args) {
36+
const inBuf = new Uint8Array(input);
37+
const compressed = lz4.compress(inBuf);
38+
return compressed.buffer;
39+
}
40+
41+
}
42+
43+
export default LZ4Compress;

src/core/operations/LZ4Decompress.mjs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @author n1474335 [[email protected]]
3+
* @copyright Crown Copyright 2022
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
import lz4 from "lz4js";
9+
10+
/**
11+
* LZ4 Decompress operation
12+
*/
13+
class LZ4Decompress extends Operation {
14+
15+
/**
16+
* LZ4Decompress constructor
17+
*/
18+
constructor() {
19+
super();
20+
21+
this.name = "LZ4 Decompress";
22+
this.module = "Compression";
23+
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.";
24+
this.infoURL = "https://wikipedia.org/wiki/LZ4_(compression_algorithm)";
25+
this.inputType = "ArrayBuffer";
26+
this.outputType = "ArrayBuffer";
27+
this.args = [];
28+
}
29+
30+
/**
31+
* @param {ArrayBuffer} input
32+
* @param {Object[]} args
33+
* @returns {ArrayBuffer}
34+
*/
35+
run(input, args) {
36+
const inBuf = new Uint8Array(input);
37+
const decompressed = lz4.decompress(inBuf);
38+
return decompressed.buffer;
39+
}
40+
41+
}
42+
43+
export default LZ4Decompress;

tests/operations/tests/Compress.mjs

+30
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,34 @@ TestRegister.addTests([
7575
}
7676
],
7777
},
78+
{
79+
name: "LZ4 Compress",
80+
input: "The cat sat on the mat.",
81+
expectedOutput: "04224d184070df170000805468652063617420736174206f6e20746865206d61742e00000000",
82+
recipeConfig: [
83+
{
84+
"op": "LZ4 Compress",
85+
"args": []
86+
},
87+
{
88+
"op": "To Hex",
89+
"args": ["None", 0]
90+
}
91+
],
92+
},
93+
{
94+
name: "LZ4 Decompress",
95+
input: "04224d184070df170000805468652063617420736174206f6e20746865206d61742e00000000",
96+
expectedOutput: "The cat sat on the mat.",
97+
recipeConfig: [
98+
{
99+
"op": "From Hex",
100+
"args": ["None"]
101+
},
102+
{
103+
"op": "LZ4 Decompress",
104+
"args": []
105+
}
106+
],
107+
},
78108
]);

0 commit comments

Comments
 (0)