/** * @author n1474335 [n1474335@gmail.com] * @copyright Crown Copyright 2016 * @license Apache-2.0 */ import Operation from "../Operation.mjs"; import cptable from "codepage"; import {CHR_ENC_CODE_PAGES} from "../lib/ChrEnc.mjs"; /** * Decode text operation */ class DecodeText extends Operation { /** * DecodeText constructor */ constructor() { super(); this.name = "Decode text"; this.module = "Encodings"; this.description = [ "Decodes text from the chosen character encoding.", "

", "Supported charsets are:", "", ].join("\n"); this.infoURL = "https://wikipedia.org/wiki/Character_encoding"; this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { "name": "Encoding", "type": "option", "value": Object.keys(CHR_ENC_CODE_PAGES) } ]; } /** * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { const format = CHR_ENC_CODE_PAGES[args[0]]; return cptable.utils.decode(format, new Uint8Array(input)); } } export default DecodeText;