mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Remove padLeft & move zeroFillBytes to Utils
+ `padLeft was changed to use `Utils.padLeft` + Moved `zeroFillBytes` to `Utils.padBytesRight`
This commit is contained in:
parent
037540c9a8
commit
bbc93af2ae
2 changed files with 45 additions and 36 deletions
|
@ -93,6 +93,34 @@ var Utils = {
|
|||
},
|
||||
|
||||
|
||||
/**
|
||||
* Adds trailing bytes to a byteArray.
|
||||
*
|
||||
* @param {byteArray} arr - byteArray to add trailing bytes to.
|
||||
* @param {number} numBytes - Maximum width of the array.
|
||||
* @param {Integer} [padByte=0] - The byte to pad with.
|
||||
* @returns {byteArray}
|
||||
*
|
||||
* @example
|
||||
* // returns "['a', 0, 0, 0]"
|
||||
* Utils.padBytesRight("a", 4);
|
||||
*
|
||||
* // returns "['a', 1, 1, 1]"
|
||||
* Utils.padBytesRight("a", 4, 1);
|
||||
*/
|
||||
padBytesRight: function(arr, numBytes, padByte) {
|
||||
padByte = padByte || 0;
|
||||
var paddedBytes = new Array(numBytes);
|
||||
paddedBytes.fill(padByte);
|
||||
|
||||
Array.prototype.map.call(arr, function(b, i) {
|
||||
paddedBytes[i] = b;
|
||||
});
|
||||
|
||||
return paddedBytes;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @alias Utils.padLeft
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue