Terrain50Renderer: Improve logging

This commit is contained in:
Starbeamrainbowlabs 2021-01-25 17:38:00 +00:00
parent f01331b8f0
commit 1b92d523f6
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 23 additions and 2 deletions

View File

@ -0,0 +1,20 @@
"use strict";
/**
* Converts a filesize into a human-readable string.
* Ported from PHP: https://github.com/sbrl/Pepperminty-Wiki/blob/0a81c940c5803856db250b29f54658476bc81e21/core/05-functions.php#L57-L73
* @see http://php.net/manual/en/function.filesize.php#106569 The original source
* @author rommel
* @author Edited by Starbeamrainbowlabs
* @param {number} bytes The number of bytes to convert.
* @param {number} decimals The number of decimal places to preserve.
* @return {string} A human-readable filesize.
*/
function human_filesize(bytes, decimals = 2) {
let sz = ["b", "kib", "mib", "gib", "tib", "pib", "eib", "yib", "zib"];
let factor = Math.floor((bytes.toString().length - 1) / 3);
let result = Math.round(bytes / (1024 ** factor), decimals);
return result + sz[factor];
}
export default human_filesize;

View File

@ -5,6 +5,8 @@ import encode from 'image-encode';
import l from '../../Helpers/Log.mjs';
import human_filesize from '../../Helpers/human_filesize.mjs';
class Terrain50Renderer {
constructor(in_scale_factor, in_domain = "auto") {
this.colour_domain = in_domain;
@ -114,8 +116,7 @@ class Terrain50Renderer {
}
}
l.log(`Written to ${count} pixels (${view32.length} present, ${((count/(width*height))*100).toFixed(2)}%)`);
console.log(view8);
l.log(`Written to ${count} pixels (${view32.length} present, ${((count/(width*height))*100).toFixed(2)}%, ${human_filesize(view8.length)} total)`);
return view8;
}