Skip to content

Commit cdbe7e4

Browse files
lguerardehrenfeu
authored andcommitted
Add function to convert size from bytes to a more readable format
1 parent 7a0be28 commit cdbe7e4

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/imcflibs/imagej/misc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,23 @@ def run_imarisconvert(file_path, pixel_calibration=None, output_folder=""):
737737
else:
738738
timed_log("Error converting [%s]: %d" % (file_path, result))
739739

740+
741+
def convert_bytes(size):
742+
"""Convert size from bytes to a readable value
743+
744+
Parameters
745+
----------
746+
size : int
747+
Byte size
748+
749+
Returns
750+
-------
751+
str
752+
Easy to read value with the correct unit
753+
"""
754+
for x in ["bytes", "KB", "MB", "GB", "TB"]:
755+
if size < 1024.0:
756+
return "%3.1f %s" % (size, x)
757+
size /= 1024.0
758+
759+
return size

0 commit comments

Comments
 (0)