2018-04-02 20:46:55 +01:00
|
|
|
/**
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-07-09 12:23:59 +01:00
|
|
|
import Operation from "../Operation.mjs";
|
2019-12-16 17:05:06 +00:00
|
|
|
import gunzip from "zlibjs/bin/gunzip.min.js";
|
2018-04-02 20:46:55 +01:00
|
|
|
|
2019-12-16 17:05:06 +00:00
|
|
|
const Zlib = gunzip.Zlib;
|
2018-04-02 20:46:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gunzip operation
|
|
|
|
*/
|
|
|
|
class Gunzip extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gunzip constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Gunzip";
|
|
|
|
this.module = "Compression";
|
|
|
|
this.description = "Decompresses data which has been compressed using the deflate algorithm with gzip headers.";
|
2018-08-21 19:07:13 +01:00
|
|
|
this.infoURL = "https://wikipedia.org/wiki/Gzip";
|
2018-04-21 13:41:42 +01:00
|
|
|
this.inputType = "ArrayBuffer";
|
|
|
|
this.outputType = "ArrayBuffer";
|
2018-04-02 20:46:55 +01:00
|
|
|
this.args = [];
|
2020-03-24 11:06:37 +00:00
|
|
|
this.checks = [
|
|
|
|
{
|
|
|
|
pattern: "^\\x1f\\x8b\\x08",
|
|
|
|
flags: "",
|
|
|
|
args: []
|
2020-02-25 11:27:03 +00:00
|
|
|
}
|
2020-03-24 11:06:37 +00:00
|
|
|
];
|
2018-04-02 20:46:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-21 13:41:42 +01:00
|
|
|
* @param {ArrayBuffer} input
|
2018-04-02 20:46:55 +01:00
|
|
|
* @param {Object[]} args
|
2018-04-21 13:41:42 +01:00
|
|
|
* @returns {File}
|
2018-04-02 20:46:55 +01:00
|
|
|
*/
|
|
|
|
run(input, args) {
|
2019-12-16 17:05:06 +00:00
|
|
|
const gzipObj = new Zlib.Gunzip(new Uint8Array(input));
|
|
|
|
return new Uint8Array(gzipObj.decompress()).buffer;
|
2018-04-02 20:46:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Gunzip;
|