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 {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.";
|
2018-08-21 20:07:13 +02:00
|
|
|
this.infoURL = "https://wikipedia.org/wiki/DEFLATE";
|
2018-04-21 14:41:42 +02:00
|
|
|
this.inputType = "ArrayBuffer";
|
|
|
|
this.outputType = "ArrayBuffer";
|
2018-04-02 21:46:55 +02:00
|
|
|
this.args = [
|
|
|
|
{
|
|
|
|
name: "Compression type",
|
|
|
|
type: "option",
|
|
|
|
value: COMPRESSION_TYPE
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-21 14:41:42 +02:00
|
|
|
* @param {ArrayBuffer} input
|
2018-04-02 21:46:55 +02:00
|
|
|
* @param {Object[]} args
|
2018-04-21 14:41:42 +02:00
|
|
|
* @returns {ArrayBuffer}
|
2018-04-02 21:46:55 +02:00
|
|
|
*/
|
|
|
|
run(input, args) {
|
2018-04-21 14:41:42 +02:00
|
|
|
const deflate = new Zlib.RawDeflate(new Uint8Array(input), {
|
2018-04-02 21:46:55 +02:00
|
|
|
compressionType: RAW_COMPRESSION_TYPE_LOOKUP[args[0]]
|
|
|
|
});
|
2018-04-21 14:41:42 +02:00
|
|
|
return new Uint8Array(deflate.compress()).buffer;
|
2018-04-02 21:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RawDeflate;
|