This will probably be part of SearchLink someday, but I decided to stop adding features and get that shipped as soon as possible (just have to rewrite most of the documentation). So here’s this piece of it as a Service and a CLI.
It’s a conversion tool for file sizes. You can use it a few ways.
First, just pass a number representing bytes to it. It will find the human-readable representation of it, ranging from Kilobytes to Yottabytes. Example:
bytes.rb 10938457612 => 10.19GB
This is the same as the “to human” argument, unless the number already has a size name in it (245mb), in which case it would just return the input. If you add “to machine” to a number like that, you’ll get the byte equivalent back:
bytes.rb 245mb to machine 256901120
You can also specify what multiplier to use for machine-to-human conversion:
bytes.rb 10938457612 in mb => 10431.73MB
Human-to-human works the same way:
bytes.rb 245mb in kb => 250880.00KB
The script works with STDIN pipes or command line arguments, the former making it better for use in a Service. It will also look for its recongized syntaxes surrounded by parentheses in a larger block of text, so you can use it just like SearchLink:
The file had a size of (24mb to machine), which converted to (25165824 to human) (that’s (24mb in kb) in Kilobytes).
bytes.rb, that becomes:
The file had a size of 25165824, which converted to 24.00MB (that’s 24576.00KB in Kilobytes).
I don’t know how many people will ever have a use for this, but I liked the regex enough that I figured I should share it1. Download the System Service below, or grab the command-line script on GitHub.
To use the script, just make it executable and put it in your path. To use the Service, unzip and double click it to install, then select text containing its syntax and right click.