Human Readable File Sizes
=========================
Parses & Formats integer file sizes to human readable file sizes.
Example Usage
-------------
Parsing
~~~~~~~
::
>>> from hfilesize import Format, FileSize
>>> FileSize('1k')
... 1000
>>> FileSize('1K')
... 1024
>>> FileSize('1kib')
... 1024
>>> FileSize('1K', default_binary=False, case_sensitive=False)
... 1000
>>> FileSize('1 kibibyte')
... 1024
Formatting
~~~~~~~~~~
::
>>> '{:d}'.format(FileSize(1024))
... '1024'
>>> '{:.02fH}'.format(FileSize(1024))
... '1 KB'
>>> '{:.02fHcv}'.format(FileSize(1024))
... '1 kilobyte'
>>> '{:.02fhs}'.format(FileSize(1000))
... '1 KB'
>>> '{:.02fhs^0}'.format(FileSize(1000))
... '1000 B'
>>> '{: >10.02fH}'.format(FileSize(1024))
... ' 1 KB'
Documentation
-------------
Parsing Options
~~~~~~~~~~~~~~~
- ``case_sensitive``: Use 1024 for upper case and 1000 for lower case
if casing exists, as is common in unix utilities, e.g. dd
- ``default_binary``: Default base if it is not clear what the unit is
(i.e. if it is not 'mib' or 'mebibytes')
Formatting Options
~~~~~~~~~~~~~~~~~~
- format type: ``[hH][size_format][^exponent]``
- ``h``: Base 1000
- ``H``: Base 1024
- ``size_format``: ``c | cs | cv | e | ev | s | sv``
- ``c``: Commonly used case-sensitive suffixes
- ``cs``: Commonly used abbreviated case-sensitive suffixes
- ``cv``: Commonly used verbose case-sensitive suffixes
- ``e``: IEC suffixes
- ``ev``: IEC verbose suffixes
- ``s``: SI suffixes
- ``sv``: SI verbose suffixes
- ``exponent``: ``integer``
References
----------
Inspired by:
- ```hurry.filesize`` <https://pypi.python.org/pypi/hurry.filesize>`__
- `Human readable file/memory sizes v2 (Python
recipe) <http://code.activestate.com/recipes/578323-human-readable-filememory-sizes-v2/>`__
License
-------
Licensed under GPLv3.
Raw data
{
"_id": null,
"home_page": "https://github.com/simonzack/hfilesize",
"name": "hfilesize",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "simonzack",
"author_email": "simonzack@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/6f/29/23423e1022626fe2251fbbf3e0854c6f1e954d740537718938ba5072c8a4/hfilesize-0.1.0.zip",
"platform": "UNKNOWN",
"description": "Human Readable File Sizes\r\n=========================\r\n\r\nParses & Formats integer file sizes to human readable file sizes.\r\n\r\nExample Usage\r\n-------------\r\n\r\nParsing\r\n~~~~~~~\r\n\r\n::\r\n\r\n >>> from hfilesize import Format, FileSize\r\n >>> FileSize('1k')\r\n ... 1000\r\n >>> FileSize('1K')\r\n ... 1024\r\n >>> FileSize('1kib')\r\n ... 1024\r\n >>> FileSize('1K', default_binary=False, case_sensitive=False)\r\n ... 1000\r\n >>> FileSize('1 kibibyte')\r\n ... 1024\r\n\r\nFormatting\r\n~~~~~~~~~~\r\n\r\n::\r\n\r\n >>> '{:d}'.format(FileSize(1024))\r\n ... '1024'\r\n >>> '{:.02fH}'.format(FileSize(1024))\r\n ... '1 KB'\r\n >>> '{:.02fHcv}'.format(FileSize(1024))\r\n ... '1 kilobyte'\r\n >>> '{:.02fhs}'.format(FileSize(1000))\r\n ... '1 KB'\r\n >>> '{:.02fhs^0}'.format(FileSize(1000))\r\n ... '1000 B'\r\n >>> '{: >10.02fH}'.format(FileSize(1024))\r\n ... ' 1 KB'\r\n\r\nDocumentation\r\n-------------\r\n\r\nParsing Options\r\n~~~~~~~~~~~~~~~\r\n\r\n- ``case_sensitive``: Use 1024 for upper case and 1000 for lower case\r\n if casing exists, as is common in unix utilities, e.g. dd\r\n\r\n- ``default_binary``: Default base if it is not clear what the unit is\r\n (i.e. if it is not 'mib' or 'mebibytes')\r\n\r\nFormatting Options\r\n~~~~~~~~~~~~~~~~~~\r\n\r\n- format type: ``[hH][size_format][^exponent]``\r\n\r\n - ``h``: Base 1000\r\n - ``H``: Base 1024\r\n\r\n- ``size_format``: ``c | cs | cv | e | ev | s | sv``\r\n\r\n - ``c``: Commonly used case-sensitive suffixes\r\n - ``cs``: Commonly used abbreviated case-sensitive suffixes\r\n - ``cv``: Commonly used verbose case-sensitive suffixes\r\n - ``e``: IEC suffixes\r\n - ``ev``: IEC verbose suffixes\r\n - ``s``: SI suffixes\r\n - ``sv``: SI verbose suffixes\r\n\r\n- ``exponent``: ``integer``\r\n\r\nReferences\r\n----------\r\n\r\nInspired by:\r\n\r\n- ```hurry.filesize`` <https://pypi.python.org/pypi/hurry.filesize>`__\r\n- `Human readable file/memory sizes v2 (Python\r\n recipe) <http://code.activestate.com/recipes/578323-human-readable-filememory-sizes-v2/>`__\r\n\r\nLicense\r\n-------\r\n\r\nLicensed under GPLv3.",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "Human Readable File Sizes",
"version": "0.1.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "598f5440be97223d529c41f5be6879a7",
"sha256": "560578c395a3b9b0fd25f93c6fb75008e0797cff48b462656c2bc7373179fa30"
},
"downloads": -1,
"filename": "hfilesize-0.1.0.zip",
"has_sig": false,
"md5_digest": "598f5440be97223d529c41f5be6879a7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7409,
"upload_time": "2014-03-23T17:55:40",
"upload_time_iso_8601": "2014-03-23T17:55:40.002607Z",
"url": "https://files.pythonhosted.org/packages/6f/29/23423e1022626fe2251fbbf3e0854c6f1e954d740537718938ba5072c8a4/hfilesize-0.1.0.zip",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2014-03-23 17:55:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "simonzack",
"github_project": "hfilesize",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "hfilesize"
}