Skip to content

Add method to convert bytes #95

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions