GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - simonzack/hfilesize: Human readable file size parsing & formatting in python 3, with various notations

BranchesTags
Open more actions menu

Latest commit

 

History

40 Commits
40 Commits

Folders and files

NameName
Last commit message
Last commit date
hfilesize
hfilesize
 
 
.gitignore
.gitignore
 
 
MANIFEST.in
MANIFEST.in
 
 
pdm.lock
pdm.lock
 
 
pyproject.toml
pyproject.toml
 
 
readme.md
readme.md
 
 

Repository files navigation

Human Readable File Sizes

Parses & Formats integer file sizes to human readable file sizes.

Development Setup

To setup the project for development, run:

$ cd hfilesize/
$ pdm install

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
  • Human readable file/memory sizes v2 (Python recipe)

License

Licensed under MIT.

About

Human readable file size parsing & formatting in python 3, with various notations

Resources

Readme
Activity

Stars

10 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.