[gpodder-devel] Extended format_filesize() function to cover SI units

  • From: z0idberg at gmx.de (Gerrit Sangel)
  • Date: Thu, 1 Nov 2007 14:00:00 +0100

Hello,

Am Donnerstag 01 November 2007 schrieb Thomas Perl:
> Basically, you want to add support for the decimal output format of file
> sizes. Why keep two different options for the same thing ("off" and
> "binary"), apart from the added "i" in "MiB", "KiB" and "GiB".

Well, because I think some people would be confused if there is a ?i? between 
the prefix and the unit. But I don?t know, personally I like the ?MiB?  
better than the wrong ?MB?. I guess, MiB as standard usage would also be ok.

> I've googled a bit for the "BYTEPREFIX" environment variable, and I
> haven't found a project that uses this variable name for the same thing.

Yes, you?re right, I?ve invented it. :D

> For this reason, I am against "inventing" a standard. If there is a
> variable in POSIX or GNU that defines that behaviour, I'd be glad to add
> support for that.

Well, I thought maybe writing to a GNU mailing list for that (but I don?t 
really know if they would be open minded for that)... As far as I know, some 
GNU applications already use the binary prefixes, but I find it better if one 
could also use the SI prefixes. That way, the 500 GB hard disk would also be 
displayed as 500 GB in the system. I don?t really see a point using file 
sizes as powers of 2 with ordinary files.

> We can, however, add this as a configuration option to gpodder.conf and
> not add configuration support for it in the GUI. This way, the UI does
> not get too difficult, and interested users can still set their
> preference in gpodder.conf.

Well, ok, I guess this would be the best option, then.

> I will have a look as time permits. Here are some questions that I'm
> still not sure about:
>
>  -) What IS the standard of displaying file sizes? (KB[2], KB[10], KiB?)
>  -) What is the benefit of providing "decimal" file sizes?
>  -) It would modify the results of our speed/etc.. calculations, is
>     that something we want or should avoid?

1. As far as I know, there is no real standard. The SI prefixes (which are 
used in natural sciences) define a kilo as 10^3, a mega as 10^6, a giga as 
10^9 and so on. That way, one can easily just cut the last digits of a file 
size and get a correct file size with a prefix (e.g. 194385745 byte = 194,39 
MB) without using a calculator.
Hard disk manufacturers also use them. That way, a 500 GB hdd has really 500 
billion bytes. 
The problem now is that in the past, the kilo, mega and so on prefixes were 
used as 2^10, 2^20, 2^30 etc. But that?s incorrect, kilo etc. are defined as 
10^3 etc. For this confusion to end, the binary prefixes were invented. That 
way, a kibi is 2^10. 

In short: kB for 1000 Bytes and KiB for 1024 Bytes are correct, but kB for 
1024 Byte is incorrect. 

2. Well, it is the correct usage of the SI prefixes. :D The problem is that 
the hdd manufacturers use the SI prefixes correctly (ok, they do that because 
they can advertise ?more? space than there really is, but the thing is, they 
are correct whether the customer likes it or not). But almost all software 
products don?t use them correctly. That?s also a reason because I thought of 
an ?off? setting. 
I personally would really like to use the SI prefixes in my applications. If I 
have a MiB, I would still have to convert them to SI prefixes. I really don?t 
see the point why I should use another prefix just because it is a byte and 
not, say, a meter.

I guess, the main purpose of the binary prefixes is to clarify that kilo is 
only 1000, not 1024.

3. I don?t really know. But because the format_filesize() function returns a 
string, I guess it is not used for calculations, just for display? That way, 
I don?t think it would do any harm. I guess, gpodder uses a byte size without 
any prefix for calculations? This is the same in all versions. 20000 Byte are 
always 20000 Byte.

You might want to take a look at these:

http://en.wikipedia.org/wiki/Binary_prefix
http://de.wikipedia.org/wiki/Bin%C3%A4rpr%C3%A4fix
http://de.wikipedia.org/wiki/SI-Pr%C3%A4fix

Oh, I just saw, the symbol for kilo is k, not K. My mistake.

Gerrit


Other related posts: