'To Base64' and 'To Hexdump' operations now support ArrayBuffers

This commit is contained in:
n1474335 2017-12-28 15:59:58 +00:00
parent 849d41ee56
commit 75a554e215
4 changed files with 11 additions and 10 deletions

View file

@ -438,7 +438,7 @@ const Utils = {
/**
* Converts a charcode array to a string.
*
* @param {byteArray} byteArray
* @param {byteArray|Uint8Array} byteArray
* @returns {string}
*
* @example
@ -477,7 +477,7 @@ const Utils = {
/**
* Base64's the input byte array using the given alphabet, returning a string.
*
* @param {byteArray|string} data
* @param {byteArray|Uint8Array|string} data
* @param {string} [alphabet]
* @returns {string}
*

View file

@ -245,7 +245,7 @@ const OperationConfig = {
description: "Base64 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.<br><br>This operation encodes data in an ASCII Base64 string.<br><br>e.g. <code>hello</code> becomes <code>aGVsbG8=</code>",
highlight: "func",
highlightReverse: "func",
inputType: "byteArray",
inputType: "ArrayBuffer",
outputType: "string",
args: [
{
@ -782,7 +782,7 @@ const OperationConfig = {
description: "Creates a hexdump of the input data, displaying both the hexadecimal values of each byte and an ASCII representation alongside.",
highlight: "func",
highlightReverse: "func",
inputType: "byteArray",
inputType: "ArrayBuffer",
outputType: "string",
args: [
{

View file

@ -40,13 +40,13 @@ const Base64 = {
/**
* To Base64 operation.
*
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
runTo: function(input, args) {
const alphabet = args[0] || Base64.ALPHABET;
return Utils.toBase64(input, alphabet);
return Utils.toBase64(new Uint8Array(input), alphabet);
},

View file

@ -31,18 +31,19 @@ const Hexdump = {
/**
* To Hexdump operation.
*
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
runTo: function(input, args) {
const data = new Uint8Array(input);
const length = args[0] || Hexdump.WIDTH;
const upperCase = args[1];
const includeFinalLength = args[2];
let output = "", padding = 2;
for (let i = 0; i < input.length; i += length) {
const buff = input.slice(i, i+length);
for (let i = 0; i < data.length; i += length) {
const buff = data.slice(i, i+length);
let hexa = "";
for (let j = 0; j < buff.length; j++) {
hexa += Utils.hex(buff[j], padding) + " ";
@ -59,7 +60,7 @@ const Hexdump = {
hexa.padEnd(length*(padding+1), " ") +
" |" + Utils.printable(Utils.byteArrayToChars(buff)).padEnd(buff.length, " ") + "|\n";
if (includeFinalLength && i+buff.length === input.length) {
if (includeFinalLength && i+buff.length === data.length) {
output += Utils.hex(i+buff.length, 8) + "\n";
}
}