Format...:Bytes(3pm)

πŸ“¦
version 0.06 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Format::Human::Bytes β€” the manual, but make it cute πŸ’–

okay bestie, so this is Format::Human::Bytes, a little Perl module that lives in the User Contributed Perl Documentation section of the manual. She's on version 0.06 and honestly? she's iconic. Let's get into it. πŸ¦‹


✨ NAME ✨

Format::Human::Bytes β€” format a bytecount and make it human readable πŸ’…

Like, the whole point. Bytes in, vibes out.


🌸 VERSION 🌸

Version 0.06. periodt.


πŸŽ€ SYNOPSIS πŸŽ€

Ever showed 12345678 bytes to a user instead of just saying 11MB?? 😭 Not the move. This module hands you back a printable string that actual humans can read, instead of a raw bytecount screaming for help.

use Format::Human::Bytes;

$readable = Format::Human::Bytes::base2($bytecount[,$decimals]);
$readable = Format::Human::Bytes::base10($bytecount[,$decimals]);

$readable = Format::Human::Bytes->base2($bytecount[,$decimals]);
$readable = Format::Human::Bytes->base10($bytecount[,$decimals]);

my $fhb = Format::Human::Bytes->new();
$readable = $fhb->base2($bytecount[,$decimals]);
$readable = $fhb->base10($bytecount[,$decimals]);

All the functions do an "intelligent" switch to the next unit when it's time, like:

1000 => 1000B
[...]
8000 => 8000B
9000 => 9kB

The way that the difference between 1000 bytes and 1500 bytes usually hits way harder (say, because of a slow link) than the difference between 95kB and 95,5kB?? Yeah. Same energy applies to 8000kB vs. 9 MB and to all the other units. πŸ”₯

Depending on how you're using this, you might wanna say how many decimals you want shown β€” and heads up, it defaults to no decimals. πŸ™ˆ


🫢 FUNCTIONS / METHODS 🫢

🌟 new

my $fhb = Format::Human::Bytes->new();

Creates and returns a Format::Human::Bytes object. That's it, that's the whole job. She's lowkey just here to exist. ✨

πŸ’œ base2

Callable as a function:

$readable = Format::Human::Bytes::base2($bytecount[,$decimals]);

Callable as a class method:

$readable = Format::Human::Bytes->base2($bytecount[,$decimals]);

Callable as an object method:

$readable = $fhb->base2($bytecount[,$decimals]);

Returns the correct readable form of the bytecount you gave it.

"Correct" here means 1kB is 1024 Bytes β€” which is literally how computers see the world. πŸ‘‘

If you pass a decimal parameter, the resulting number will have exactly the number of decimal numbers you specified.

πŸ¦‹ base10

Callable as a function:

$readable = Format::Human::Bytes::base10($bytecount[,$decimals]);

Callable as a class method:

$readable = Format::Human::Bytes->base10($bytecount[,$decimals]);

Callable as an object method:

$readable = $fhb->base10($bytecount[,$decimals]);

Returns the incorrect readable form of the bytecount you gave it. 😭

"Incorrect" here means 1kB is 1000 Bytes and 1 MB is 1000000 bytes β€” which is how some (many) people see the world, but it's wrong for computers. not me exposing the entire metric system πŸ’€

If you pass a decimal parameter, the resulting number will have exactly the number of decimal numbers you specified.


πŸ‘‘ AUTHOR πŸ‘‘

Sebastian Willing, "<sewi at cpan.org>" β€” the icon who wrote this, we stan 🫢


πŸ’€ BUGS πŸ’€

Please report any bugs or feature requests to "bug-format-human-bytes at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Format-Human-Bytes>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. fr fr, they'll ping you back. πŸ“¬


🌈 SUPPORT 🌈

You can find documentation for this module with the perldoc command.

perldoc Format::Human::Bytes

You can also look for information at:

  • RT: CPAN's request tracker

<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Format-Human-Bytes>

  • AnnoCPAN: Annotated CPAN documentation

<http://annocpan.org/dist/Format-Human-Bytes>

  • CPAN Ratings

<http://cpanratings.perl.org/d/Format-Human-Bytes>

  • Search CPAN

<http://search.cpan.org/dist/Format-Human-Bytes/>


⭐ HISTORY ⭐

The functions are in use since late 2003 or early 2004 but I didn't pack them for CPAN before 2009. two-thousand-late-2003?? she was serving before she even had a CPAN release, main character energy honestly πŸ’…


πŸ“ LICENSE πŸ“

This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. slay. πŸŽ€


okay that's the whole page bestie, go format some bytes and go off ✨

Brought to you by perl v5.34.0 on 2022-06-14 β€” that's the version and date this page was generated, mwah πŸ’–

πŸ“¦ where this page comes from