Skip to content

Commit 25b16a3

Browse files
committed
Add function to convert size from bytes to a more readable format
1 parent 205869c commit 25b16a3

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
@@ -711,3 +711,23 @@ def run_imarisconvert(file_path, pixel_calibration=None):
711711
IJ.log("Conversion to .ims is finished.")
712712
else:
713713
IJ.log("Conversion failed with error code: %d" % result)
714+
715+
def convert_bytes(size):
716+
"""Convert size from bytes to a readable value
717+
718+
Parameters
719+
----------
720+
size : int
721+
Byte size
722+
723+
Returns
724+
-------
725+
str
726+
Easy to read value with the correct unit
727+
"""
728+
for x in ["bytes", "KB", "MB", "GB", "TB"]:
729+
if size < 1024.0:
730+
return "%3.1f %s" % (size, x)
731+
size /= 1024.0
732+
733+
return size

0 commit comments

Comments
 (0)