Remove padLeft & move zeroFillBytes to Utils

+ `padLeft was changed to use `Utils.padLeft`
+ Moved `zeroFillBytes` to `Utils.padBytesRight`
This commit is contained in:
toby 2017-02-09 13:07:46 -05:00
parent 037540c9a8
commit bbc93af2ae
2 changed files with 45 additions and 36 deletions

View file

@ -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
*/