defdo_filesizeformat(value:t.Union[str,float,int],binary:bool=False)->str:"""Format the value like a 'human-readable' file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega, Giga, etc.), if the second parameter is set to `True` the binary prefixes are used (Mebi, Gibi). """bytes=float(value)base=1024ifbinaryelse1000prefixes=[("KiB"ifbinaryelse"kB"),("MiB"ifbinaryelse"MB"),("GiB"ifbinaryelse"GB"),("TiB"ifbinaryelse"TB"),("PiB"ifbinaryelse"PB"),("EiB"ifbinaryelse"EB"),("ZiB"ifbinaryelse"ZB"),("YiB"ifbinaryelse"YB"),]ifbytes==1:return"1 Byte"elifbytes<base:returnf"{int(bytes)} Bytes"else:fori,prefixinenumerate(prefixes):unit=base**(i+2)ifbytes<unit:returnf"{base*bytes/unit:.1f}{prefix}"returnf"{base*bytes/unit:.1f}{prefix}"