mirror of
https://github.com/sbrl/terrain50-cli.git
synced 2024-11-22 06:53:01 +00:00
Terrain50Renderer: Improve logging
This commit is contained in:
parent
f01331b8f0
commit
1b92d523f6
2 changed files with 23 additions and 2 deletions
20
src/Helpers/human_filesize.mjs
Normal file
20
src/Helpers/human_filesize.mjs
Normal 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;
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue