0.0
Repository is archived
Accepts a file size in bytes and returns a string with the appropriate prefix (e.g., '1.5 MB', '1024 KB').
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Human File Size

Gem Version

Human File Size is a simple Gem for formatting file sizes into a human-readable format.

Installation

Add this line to your application's Gemfile:

gem 'human_file_size'

And then execute:

bundle install

Or install it yourself as:

gem install human_file_size

Usage

require 'human_file_size'

HumanFileSize.format(100)          # => "100.00 B"
HumanFileSize.format(1024)         # => "1.00 KB"
HumanFileSize.format(1536)         # => "1.50 KB"
HumanFileSize.format(1048576)      # => "1.00 MB"
HumanFileSize.format(2621440, precision: 1) # => "2.5 MB"
HumanFileSize.format(1572864576)   # => "1.50 GB"

License

This Gem is distributed under the MIT License. See the LICENSE.txt fire for details

Author