INNER CODE UNIT · JavaScript

calculateBytes

jofpin/temcrypt · temcrypt.js:223

            const calculateBytes = function(bytes) {
                const units = ["Bytes", "KB", "MB", "GB"];
                const kbytes = 1024;

                if (bytes === 0) {
                    return "0 Bytes";
                }

                const index = Math.floor(Math.log(bytes) / Math.log(kbytes));
                const convertBytes = bytes / Math.pow(kbytes, index);
                const formatBytes = convertBytes % 1 === 0 ? convertBytes.toFixed(0) : convertBytes.toFixed(2);

                return `${formatBytes} ${units[index]}`;
            };

            return { sha256, enc256, dec256, splitKey, readerFile, writerFile, outputFilename, calculateBytes }

        },

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…