mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
ESM: Added Zlib ops and created a Zlib library.
This commit is contained in:
parent
fbb3a02315
commit
083d2d1cc4
16 changed files with 913 additions and 350 deletions
58
src/core/operations/RawDeflate.mjs
Normal file
58
src/core/operations/RawDeflate.mjs
Normal file
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import {COMPRESSION_TYPE} from "../lib/Zlib";
|
||||
import rawdeflate from "zlibjs/bin/rawdeflate.min";
|
||||
|
||||
const Zlib = rawdeflate.Zlib;
|
||||
|
||||
const RAW_COMPRESSION_TYPE_LOOKUP = {
|
||||
"Fixed Huffman Coding": Zlib.RawDeflate.CompressionType.FIXED,
|
||||
"Dynamic Huffman Coding": Zlib.RawDeflate.CompressionType.DYNAMIC,
|
||||
"None (Store)": Zlib.RawDeflate.CompressionType.NONE,
|
||||
};
|
||||
|
||||
/**
|
||||
* Raw Deflate operation
|
||||
*/
|
||||
class RawDeflate extends Operation {
|
||||
|
||||
/**
|
||||
* RawDeflate constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Raw Deflate";
|
||||
this.module = "Compression";
|
||||
this.description = "Compresses data using the deflate algorithm with no headers.";
|
||||
this.inputType = "byteArray";
|
||||
this.outputType = "byteArray";
|
||||
this.args = [
|
||||
{
|
||||
name: "Compression type",
|
||||
type: "option",
|
||||
value: COMPRESSION_TYPE
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
const deflate = new Zlib.RawDeflate(input, {
|
||||
compressionType: RAW_COMPRESSION_TYPE_LOOKUP[args[0]]
|
||||
});
|
||||
return Array.prototype.slice.call(deflate.compress());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default RawDeflate;
|
Loading…
Add table
Add a link
Reference in a new issue