Skip to content

Add method to convert bytes #95

Closed
Closed
@lguerard

Description

@lguerard

@CellKai made this method already, it would be nice to integrate it to the libs.

def convert_bytes(size):
    """Convert size from bytes to a readable value

    Parameters
    ----------
    size : int
        Byte size

    Returns
    -------
    str
        Easy to read value with the correct unit
    """
    for x in ["bytes", "KB", "MB", "GB", "TB"]:
        if size < 1024.0:
            return "%3.1f %s" % (size, x)
        size /= 1024.0

    return size

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions