File perl-Number-Bytes-Human.spec of Package perl-Number-Bytes-Human

#
# spec file for package perl-Number-Bytes-Human
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           perl-Number-Bytes-Human
Version:        0.11
Release:        0
%define cpan_name Number-Bytes-Human
Summary:        Convert byte count to human readable format
License:        Artistic-1.0 or GPL-1.0+
Group:          Development/Libraries/Perl
Url:            http://search.cpan.org/dist/Number-Bytes-Human/
Source0:        http://www.cpan.org/authors/id/F/FE/FERREIRA/%{cpan_name}-%{version}.tar.gz
Source1:        cpanspec.yml
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  perl
BuildRequires:  perl-macros
%{perl_requires}

%description
THIS IS ALPHA SOFTWARE: THE DOCUMENTATION AND THE CODE WILL SUFFER CHANGES
SOME DAY (THANKS, GOD!).

This module provides a formatter which turns byte counts to usual readable
format, like '2.0K', '3.1G', '100B'. It was inspired in the '-h' option of
Unix utilities like 'du', 'df' and 'ls' for "human-readable" output.

From the FreeBSD man page of 'df':
http://www.freebsd.org/cgi/man.cgi?query=df

  "Human-readable" output.  Use unit suffixes: Byte, Kilobyte,
  Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the
  number of digits to four or fewer using base 2 for sizes.

  byte      B
  kilobyte  K = 2**10 B = 1024 B
  megabyte  M = 2**20 B = 1024 * 1024 B
  gigabyte  G = 2**30 B = 1024 * 1024 * 1024 B
  terabyte  T = 2**40 B = 1024 * 1024 * 1024 * 1024 B

  petabyte  P = 2**50 B = 1024 * 1024 * 1024 * 1024 * 1024 B
  exabyte   E = 2**60 B = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 B
  zettabyte Z = 2**70 B = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 B
  yottabyte Y = 2**80 B = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 B

I have found this link to be quite useful:

  http://www.t1shopper.com/tools/calculate/

If you feel like a hard-drive manufacturer, you can start counting bytes by
powers of 1000 (instead of the generous 1024). Just use 'bs => 1000'.

But if you are a floppy disk manufacturer and want to start counting in
units of 1024000 (for your "1.44 MB" disks)? Then use 'bs => 1_024_000'.

If you feel like a purist academic, you can force the use of metric
prefixes according to the Dec 1998 standard by the IEC. Never mind the
units for base 1000 are '('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB',
'YB')' and, even worse, the ones for base 1024 are '('B', 'KiB', 'MiB',
'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')' with the horrible names: bytes,
kibibytes, mebibytes, etc. All you have to do is to use 'si => 1'. Ain't
that beautiful the SI system? Read about it:

  http://physics.nist.gov/cuu/Units/binary.html

You can try a pure Perl '"ls -lh"'-inspired command with the one-liner, er,
two-liner:

  $ perl -MNumber::Bytes::Human=format_bytes \
         -e 'printf "%5s %s\n", format_bytes(-s), $_ for @ARGV' *

Why to write such a module? Because if people can write such things in C,
it can be written much easier in Perl and then reused, refactored, abused.
And then, when it is much improved, some brave soul can port it back to C
(if only for the warm feeling of painful programming).

It is also possible to parse human readable formatted bytes. The automatic
format detection recognizes SI units with the blocksizes of 1000 and 1024
respectively and additionally the customary K / M / G etc. with blocksize
1024. When si => 1 is added to the options only SI units are recognized.
Explicitly specifying a blocksize changes it for all detected units.

%prep
%setup -q -n %{cpan_name}-%{version}
find . -type f ! -name \*.pl -print0 | xargs -0 chmod 644

%build
%{__perl} Makefile.PL INSTALLDIRS=vendor
%{__make} %{?_smp_mflags}

%check
%{__make} test

%install
%perl_make_install
%perl_process_packlist
%perl_gen_filelist

%files -f %{name}.files
%defattr(-,root,root,755)
%doc Changes README

%changelog
openSUSE Build Service is sponsored by