From 6d18fd1428d0c01806db6a26399539870656d0f2 Mon Sep 17 00:00:00 2001 From: Eduardo Grajales Villanueva Date: Wed, 13 Jul 2022 18:45:45 -0500 Subject: [PATCH] Remove quintetCount function with Math.ceil instead --- lib/thirty-two/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/thirty-two/index.js b/lib/thirty-two/index.js index ed576e5..ae84ffb 100644 --- a/lib/thirty-two/index.js +++ b/lib/thirty-two/index.js @@ -34,10 +34,6 @@ var byteTable = [ 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff ]; -function quintetCount(buff) { - var quintets = Math.floor(buff.length / 5); - return buff.length % 5 === 0 ? quintets : quintets + 1; -} var encode = function (plain) { if (!Buffer.isBuffer(plain) && typeof plain !== "string") { throw new TypeError("base32.encode only takes Buffer or string as parameter"); @@ -49,7 +45,7 @@ var encode = function (plain) { var j = 0; var shiftIndex = 0; var digit = 0; - var encoded = Buffer.alloc(quintetCount(plain) * 8); + var encoded = Buffer.alloc(Math.ceil(plain.length / 5) * 8); /* byte by byte isn't as pretty as quintet by quintet but tests a bit faster. will have to revisit. */ while (i < plain.length) {