Skip to content

Commit 75a554e

Browse files
committed
'To Base64' and 'To Hexdump' operations now support ArrayBuffers
1 parent 849d41e commit 75a554e

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/core/Utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ const Utils = {
438438
/**
439439
* Converts a charcode array to a string.
440440
*
441-
* @param {byteArray} byteArray
441+
* @param {byteArray|Uint8Array} byteArray
442442
* @returns {string}
443443
*
444444
* @example
@@ -477,7 +477,7 @@ const Utils = {
477477
/**
478478
* Base64's the input byte array using the given alphabet, returning a string.
479479
*
480-
* @param {byteArray|string} data
480+
* @param {byteArray|Uint8Array|string} data
481481
* @param {string} [alphabet]
482482
* @returns {string}
483483
*

src/core/config/OperationConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ const OperationConfig = {
245245
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>",
246246
highlight: "func",
247247
highlightReverse: "func",
248-
inputType: "byteArray",
248+
inputType: "ArrayBuffer",
249249
outputType: "string",
250250
args: [
251251
{
@@ -782,7 +782,7 @@ const OperationConfig = {
782782
description: "Creates a hexdump of the input data, displaying both the hexadecimal values of each byte and an ASCII representation alongside.",
783783
highlight: "func",
784784
highlightReverse: "func",
785-
inputType: "byteArray",
785+
inputType: "ArrayBuffer",
786786
outputType: "string",
787787
args: [
788788
{

src/core/operations/Base64.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ const Base64 = {
4040
/**
4141
* To Base64 operation.
4242
*
43-
* @param {byteArray} input
43+
* @param {ArrayBuffer} input
4444
* @param {Object[]} args
4545
* @returns {string}
4646
*/
4747
runTo: function(input, args) {
4848
const alphabet = args[0] || Base64.ALPHABET;
49-
return Utils.toBase64(input, alphabet);
49+
return Utils.toBase64(new Uint8Array(input), alphabet);
5050
},
5151

5252

src/core/operations/Hexdump.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ const Hexdump = {
3131
/**
3232
* To Hexdump operation.
3333
*
34-
* @param {byteArray} input
34+
* @param {ArrayBuffer} input
3535
* @param {Object[]} args
3636
* @returns {string}
3737
*/
3838
runTo: function(input, args) {
39+
const data = new Uint8Array(input);
3940
const length = args[0] || Hexdump.WIDTH;
4041
const upperCase = args[1];
4142
const includeFinalLength = args[2];
4243

4344
let output = "", padding = 2;
44-
for (let i = 0; i < input.length; i += length) {
45-
const buff = input.slice(i, i+length);
45+
for (let i = 0; i < data.length; i += length) {
46+
const buff = data.slice(i, i+length);
4647
let hexa = "";
4748
for (let j = 0; j < buff.length; j++) {
4849
hexa += Utils.hex(buff[j], padding) + " ";
@@ -59,7 +60,7 @@ const Hexdump = {
5960
hexa.padEnd(length*(padding+1), " ") +
6061
" |" + Utils.printable(Utils.byteArrayToChars(buff)).padEnd(buff.length, " ") + "|\n";
6162

62-
if (includeFinalLength && i+buff.length === input.length) {
63+
if (includeFinalLength && i+buff.length === data.length) {
6364
output += Utils.hex(i+buff.length, 8) + "\n";
6465
}
6566
}

0 commit comments

Comments
 (0)