File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -275,3 +275,21 @@ def is_mergin_config(path: str) -> bool:
275275 """Check if the given path is for file mergin-config.json"""
276276 filename = os .path .basename (path ).lower ()
277277 return filename == "mergin-config.json"
278+
279+ def bytes_to_human_size (bytes : int ):
280+ """
281+ Convert bytes to human readable size
282+ example :
283+ bytes_to_human_size(5600000) -> "5.3 MB"
284+ """
285+ precision = 1 ;
286+ if ( bytes < 1e-5 ):
287+ return "0.0 MB" ;
288+ elif ( bytes < 1024.0 * 1024.0 ):
289+ return f"{ round ( bytes / 1024.0 , precision )} KB" ;
290+ elif ( bytes < 1024.0 * 1024.0 * 1024.0 ):
291+ return f"{ round ( bytes / 1024.0 / 1024.0 , precision )} MB" ;
292+ elif ( bytes < 1024.0 * 1024.0 * 1024.0 * 1024.0 ):
293+ return f"{ round ( bytes / 1024.0 / 1024.0 / 1024.0 , precision )} GB" ;
294+ else :
295+ return f"{ round ( bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0 , precision )} TB" ;
You can’t perform that action at this time.
0 commit comments