File Size Formatter API - Ruby Gem
File Size Formatter is a tool for converting bytes to human-readable file sizes (KB, MB, GB, TB, etc.). It supports both binary (1024) and decimal (1000) standards with customizable precision.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_filesizeformatter'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_filesizeformatter
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_filesizeformatter'
# Initialize the client
client = APIVerve::Filesizeformatter::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({
bytes: 1073741824,
unit: "GB",
precision: 2,
standard: "binary"
})
# Print the response
puts response
Error Handling
begin
response = client.execute({ bytes: 1073741824, unit: "GB", precision: 2, standard: "binary" })
puts response["data"]
rescue APIVerve::Filesizeformatter::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Filesizeformatter::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Filesizeformatter::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"bytes": 1073741824,
"formatted": "1 GiB",
"value": 1,
"unit": "GiB",
"standard": "binary",
"precision": 2,
"conversions": {
"B": 1073741824,
"KiB": 1048576,
"MiB": 1024,
"GiB": 1,
"TiB": 0,
"PiB": 0,
"EiB": 0,
"ZiB": 0,
"YiB": 0
}
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/filesizeformatter?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.