Added File and JSON Dish types and updated types for compression ops.

This commit is contained in:
n1474335 2018-04-21 13:41:42 +01:00
parent 76a066ab74
commit a8aa1bc5e8
9 changed files with 94 additions and 59 deletions

View file

@ -5,7 +5,6 @@
*/
import Operation from "../Operation";
import Utils from "../Utils";
import zlibAndGzip from "zlibjs/bin/zlib_and_gzip.min";
const Zlib = zlibAndGzip.Zlib;
@ -24,21 +23,19 @@ class Gunzip extends Operation {
this.name = "Gunzip";
this.module = "Compression";
this.description = "Decompresses data which has been compressed using the deflate algorithm with gzip headers.";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [];
}
/**
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
* @returns {File}
*/
run(input, args) {
// Deal with character encoding issues
input = Utils.strToByteArray(Utils.byteArrayToUtf8(input));
const gunzip = new Zlib.Gunzip(input);
return Array.prototype.slice.call(gunzip.decompress());
const gunzip = new Zlib.Gunzip(new Uint8Array(input));
return new Uint8Array(gunzip.decompress()).buffer;
}
}

View file

@ -24,8 +24,8 @@ class Gzip extends Operation {
this.name = "Gzip";
this.module = "Compression";
this.description = "Compresses data using the deflate algorithm with gzip headers.";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [
{
name: "Compression type",
@ -51,9 +51,9 @@ class Gzip extends Operation {
}
/**
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
* @returns {ArrayBuffer}
*/
run(input, args) {
const filename = args[1],
@ -76,8 +76,8 @@ class Gzip extends Operation {
options.comment = comment;
}
const gzip = new Zlib.Gzip(input, options);
return Array.prototype.slice.call(gzip.compress());
const gzip = new Zlib.Gzip(new Uint8Array(input), options);
return new Uint8Array(gzip.compress()).buffer;
}
}

View file

@ -30,8 +30,8 @@ class RawDeflate extends Operation {
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.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [
{
name: "Compression type",
@ -42,15 +42,15 @@ class RawDeflate extends Operation {
}
/**
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
* @returns {ArrayBuffer}
*/
run(input, args) {
const deflate = new Zlib.RawDeflate(input, {
const deflate = new Zlib.RawDeflate(new Uint8Array(input), {
compressionType: RAW_COMPRESSION_TYPE_LOOKUP[args[0]]
});
return Array.prototype.slice.call(deflate.compress());
return new Uint8Array(deflate.compress()).buffer;
}
}

View file

@ -5,7 +5,6 @@
*/
import Operation from "../Operation";
import Utils from "../Utils";
import {INFLATE_BUFFER_TYPE} from "../lib/Zlib";
import rawinflate from "zlibjs/bin/rawinflate.min";
@ -30,8 +29,8 @@ class RawInflate extends Operation {
this.name = "Raw Inflate";
this.module = "Compression";
this.description = "Decompresses data which has been compressed using the deflate algorithm with no headers.";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [
{
name: "Start index",
@ -62,21 +61,19 @@ class RawInflate extends Operation {
}
/**
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
* @returns {ArrayBuffer}
*/
run(input, args) {
// Deal with character encoding issues
input = Utils.strToByteArray(Utils.byteArrayToUtf8(input));
const inflate = new Zlib.RawInflate(input, {
const inflate = new Zlib.RawInflate(new Uint8Array(input), {
index: args[0],
bufferSize: args[1],
bufferType: RAW_BUFFER_TYPE_LOOKUP[args[2]],
resize: args[3],
verify: args[4]
}),
result = Array.prototype.slice.call(inflate.decompress());
result = new Uint8Array(inflate.decompress());
// Raw Inflate somethimes messes up and returns nonsense like this:
// ]....]....]....]....]....]....]....]....]....]....]....]....]....]...
@ -97,7 +94,7 @@ class RawInflate extends Operation {
}
}
// This seems to be the easiest way...
return result;
return result.buffer;
}
}

View file

@ -24,7 +24,7 @@ class Unzip extends Operation {
this.name = "Unzip";
this.module = "Compression";
this.description = "Decompresses data using the PKZIP algorithm and displays it per file, with support for passwords.";
this.inputType = "byteArray";
this.inputType = "ArrayBuffer";
this.outputType = "List<File>";
this.presentType = "html";
this.args = [
@ -42,7 +42,7 @@ class Unzip extends Operation {
}
/**
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {File[]}
*/
@ -51,7 +51,7 @@ class Unzip extends Operation {
password: Utils.strToByteArray(args[0]),
verify: args[1]
},
unzip = new Zlib.Unzip(input, options),
unzip = new Zlib.Unzip(new Uint8Array(input), options),
filenames = unzip.getFilenames();
return filenames.map(fileName => {

View file

@ -36,8 +36,8 @@ class Zip extends Operation {
this.name = "Zip";
this.module = "Compression";
this.description = "Compresses data using the PKZIP algorithm with the given filename.<br><br>No support for multiple files at this time.";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.inputType = "ArrayBuffer";
this.outputType = "File";
this.args = [
{
name: "Filename",
@ -73,14 +73,15 @@ class Zip extends Operation {
}
/**
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
* @returns {File}
*/
run(input, args) {
const password = Utils.strToByteArray(args[2]),
const filename = args[0],
password = Utils.strToByteArray(args[2]),
options = {
filename: Utils.strToByteArray(args[0]),
filename: Utils.strToByteArray(filename),
comment: Utils.strToByteArray(args[1]),
compressionMethod: ZIP_COMPRESSION_METHOD_LOOKUP[args[3]],
os: ZIP_OS_LOOKUP[args[4]],
@ -92,8 +93,8 @@ class Zip extends Operation {
if (password.length)
zip.setPassword(password);
zip.addFile(input, options);
return Array.prototype.slice.call(zip.compress());
zip.addFile(new Uint8Array(input), options);
return new File([zip.compress()], filename);
}
}

View file

@ -24,8 +24,8 @@ class ZlibDeflate extends Operation {
this.name = "Zlib Deflate";
this.module = "Compression";
this.description = "Compresses data using the deflate algorithm adding zlib headers.";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [
{
name: "Compression type",
@ -36,15 +36,15 @@ class ZlibDeflate extends Operation {
}
/**
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
* @returns {ArrayBuffer}
*/
run(input, args) {
const deflate = new Zlib.Deflate(input, {
const deflate = new Zlib.Deflate(new Uint8Array(input), {
compressionType: ZLIB_COMPRESSION_TYPE_LOOKUP[args[0]]
});
return Array.prototype.slice.call(deflate.compress());
return new Uint8Array(deflate.compress()).buffer;
}
}

View file

@ -5,7 +5,6 @@
*/
import Operation from "../Operation";
import Utils from "../Utils";
import {INFLATE_BUFFER_TYPE} from "../lib/Zlib";
import zlibAndGzip from "zlibjs/bin/zlib_and_gzip.min";
@ -30,8 +29,8 @@ class ZlibInflate extends Operation {
this.name = "Zlib Inflate";
this.module = "Compression";
this.description = "Decompresses data which has been compressed using the deflate algorithm with zlib headers.";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [
{
name: "Start index",
@ -62,21 +61,19 @@ class ZlibInflate extends Operation {
}
/**
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
* @returns {ArrayBuffer}
*/
run(input, args) {
// Deal with character encoding issues
input = Utils.strToByteArray(Utils.byteArrayToUtf8(input));
const inflate = new Zlib.Inflate(input, {
const inflate = new Zlib.Inflate(new Uint8Array(input), {
index: args[0],
bufferSize: args[1],
bufferType: ZLIB_BUFFER_TYPE_LOOKUP[args[2]],
resize: args[3],
verify: args[4]
});
return Array.prototype.slice.call(inflate.decompress());
return new Uint8Array(inflate.decompress()).buffer;
}
}