Skip to content

Commit

Permalink
'To Base64' and 'To Hexdump' operations now support ArrayBuffers
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Dec 28, 2017
1 parent 849d41e commit 75a554e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/core/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ const Utils = {
/**
* Converts a charcode array to a string.
*
* @param {byteArray} byteArray
* @param {byteArray|Uint8Array} byteArray
* @returns {string}
*
* @example
Expand Down Expand Up @@ -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}
*
Expand Down
4 changes: 2 additions & 2 deletions src/core/config/OperationConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/operations/Base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},


Expand Down
9 changes: 5 additions & 4 deletions src/core/operations/Hexdump.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + " ";
Expand All @@ -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";
}
}
Expand Down

0 comments on commit 75a554e

Please sign in to comment.