1.0 - 5th April 2008: Initial proposal.
1.1 - 1st July 2008: Almost finished proposal.
1.2 - 12th August 2010: Code and Unit Tests are working (wiki revision: 14)
<p>Some of my thoughts on this</p>
<ul>
<li>I think it could take third parameter $iec like
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
public function fileSize($filesize, $precision = 3, $iec = false)
]]></ac:plain-text-body></ac:macro>
When $iec is true this would produce KiB instead of KB, MiB instead of MB and so on.<br />
These are IEC standard binary prefixes that were introduced to prevent confusion with SI prefixes.<br />
SI states that kilo is 1000 and mega is 1000000 and these are also used in computer industry for hard disk capacity on customer boxes whilst Windows uses it in differnt meaning. Certainly there is a confusion. I think including binary prefixes an an option would be good addition as they are widespread in some communities and even some companies embraced it.</li>
</ul>
<ul>
<li>I think that it would be also useful to include a possibility to pass string path like fileSize("/home/user/file") on Unices and fileSize("C:\\x y<br class="atl-forced-newline" />z") on Windows boxes or even Zend_Uri instances beginning with file:// to this and make this automatically read apropriate info from filesystem and display in user friendly manner</li>
</ul>
<p>Hi, thank you for your comment. These enhancements would be really userful. I will implement them after Zend comments on this helper <ac:emoticon ac:name="smile" /></p>
<p>In Zend_Measure the differences to SI is detected by type.<br />
I think it can be assumed to this helper and the $iec parameter is no longer needed or if I wrong ?</p>
<p>It'd be useful to be able to specify which unit that should be used. This would make possible, for example, displaying a list of files with all sizes in MB even if some files are >1GB or <1MB for visual consistency.</p>
<p>Marthin, Zend_Measure_Binary has corresponding <span style="text-decoration: line-through;">bi</span> IEC suffixes<br />
eg MEGABYTE -> MEBIBYTE<br />
and looking at code now I would say it uses base 10 SI now not IEC <ac:emoticon ac:name="wink" /><br />
well actually it would be useful to have three state ('traditional', 'si', 'iec')<br />
and have $norm parameter instead of $iec taking one of these strings.</p>
<p>traditional <ac:link><ri:page ri:content-title="KILOBYTE..." /></ac:link> would mean base 2 and KB (^10), MB (^20), GB (^30)| si <ac:link><ri:page ri:content-title="KILOBYTE_SI..." /></ac:link> meaning base 10 and KB (^3) MB | iec <ac:link><ri:page ri:content-title="KIBIBYTE..." /></ac:link> meaning base 2 KiB (^10) MiB (^20) and GiB (^30)</p>
<p>and also I would like to see is_string($fileSize) -> stat FS and get info out of there</p>
<p>I have been busy recently, so I have updated code today. Now, you can choose which norm to use. I will update proposal to reflect changes in code and tests.</p>
<p>Looks nice, but what about possibility of passing a string as first parameter that would be interpreted as file path to read file size from file system?</p>
<p>Within your code you use Zend_Measure_Binary.<br />
Nice to see that my component is reused <ac:emoticon ac:name="smile" /><br />
But you miss some things:</p>
<p>1.) When you use a other component you must also write this within your proposal, section 4 dependencies.</p>
<p>2.) Zend_Measure_Binary allows also to use localized input. Which means it would recognise "1,000.00" in german as "1 000,00" in french or "1.000,00" in english. You should also support this possibility when using Zend_Measure. Therefor you must integrate a locale (getLocale/setLocale) or/and use a generalised Zend_Locale instance from registry when available. This way all components which are localizable use the same locale.</p>
<p>3.) Zend_Measure_Binary COULD convert from/to for you. You stated that this component will not do this within your initial description. The possibility is available through Zend_Measure_Binary.</p>
<p>There's nothing bad with dependencies. They only have to be listet. The complexer a functionallity is, the more dependencies you will probably have.</p>
<p>The question is also if you would have to listen sub-dependencies.<br />
Because Zend_Measure_Binary uses itself Zend_Locale_Format and Zend_Locale and Zend_Registry.<br />
And Zend_Exception is used by Zend_View_Exception.</p>
<p>You should be able to define a locale as last parameter as well, so that the output number is formatted according to that locale (and if not given the default locale is used). Also it would be nice to have a feature similar to some other formatters:</p>
<p>When you have 999,999 bytes, it results in 999.000 KB, but for 1,000,000 bytes, it should go to the next unit and display 0,9765625 MB. I'd say to make this an additional feature and not the default. This simply makes it easier for the actual application user to read.</p>
<ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Official Response</ac:parameter><ac:rich-text-body>
<p>This has been accepted to Zend Laboratory.</p>
<p>There are few concerns we would like to see worked out:</p>
<ul>
<li>Currently, there is a hidden dependency on Zend_Locale. By using Zend_Measure,<br />
Zend_Locale is included into the mix, thus, by using this seemingly simple view helper,<br />
one would be building out a Zend_Locale environment automagically which could cause some<br />
performance degradation in applications. Ideally, using Zend_Measure and Zend_Locale would be<br />
an opt-in feature to keep this lightweight.</li>
</ul>
<p>And is there a way to automatically determine the iec or si, based on Zend_Locale. <br />
Where can I learn this information? <br />
Could it be a part of this component?</p>
<p>(discussed on IRC) I didn't get an answer for almost two years, so I thought I won't finish it until end of August. But with you as a Liaison I think it's possible <ac:emoticon ac:name="smile" /> But I want to finish Zend_ShortUrl first (and then I'll un-archive it)</p>
25 Comments
comments.show.hideMay 05, 2008
Pawel Przeradowski
<p>Some of my thoughts on this</p>
<ul>
<li>I think it could take third parameter $iec like
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
public function fileSize($filesize, $precision = 3, $iec = false)
]]></ac:plain-text-body></ac:macro>
When $iec is true this would produce KiB instead of KB, MiB instead of MB and so on.<br />
These are IEC standard binary prefixes that were introduced to prevent confusion with SI prefixes.<br />
SI states that kilo is 1000 and mega is 1000000 and these are also used in computer industry for hard disk capacity on customer boxes whilst Windows uses it in differnt meaning. Certainly there is a confusion. I think including binary prefixes an an option would be good addition as they are widespread in some communities and even some companies embraced it.</li>
</ul>
<p> For further information please see <a class="external-link" href="http://en.wikipedia.org/wiki/Binary_prefix#IEC_standard_prefixes">http://en.wikipedia.org/wiki/Binary_prefix#IEC_standard_prefixes</a>.</p>
<ul>
<li>I think that it would be also useful to include a possibility to pass string path like fileSize("/home/user/file") on Unices and fileSize("C:\\x
y<br class="atl-forced-newline" />z") on Windows boxes or even Zend_Uri instances beginning with file:// to this and make this automatically read apropriate info from filesystem and display in user friendly manner</li>
</ul>
May 12, 2008
Martin Hujer
<p>Hi, thank you for your comment. These enhancements would be really userful. I will implement them after Zend comments on this helper <ac:emoticon ac:name="smile" /></p>
May 24, 2008
Martin Hujer
<p>I've updated code to allow SI units, but the Zend_Measure_Binary says, that unit of KILOBYTE_SI (=1000) is 'kB.' not 'KiB'</p>
Jul 14, 2009
Marc Bennewitz (private)
<p>In Zend_Measure the differences to SI is detected by type.<br />
I think it can be assumed to this helper and the $iec parameter is no longer needed or if I wrong ?</p>
May 14, 2008
Nathan Wright
<p>This is a much needed addition IMO.</p>
<p>It'd be useful to be able to specify which unit that should be used. This would make possible, for example, displaying a list of files with all sizes in MB even if some files are >1GB or <1MB for visual consistency.</p>
May 24, 2008
Martin Hujer
<p>Hi.</p>
<p>I've updated proposal and code to do that <ac:emoticon ac:name="smile" /></p>
May 23, 2008
Pawel Przeradowski
<p>I also noticed you do divide stuff inside your helper. I think you could reuse Zend_Measure_Binary as it already supports both SI and IEC.</p>
May 24, 2008
Martin Hujer
<p>Hi.</p>
<p>I've refactored code to use Zend_Measure_Binary.</p>
May 24, 2008
Pawel Przeradowski
<p>Marthin, Zend_Measure_Binary has corresponding <span style="text-decoration: line-through;">bi</span> IEC suffixes<br />
eg MEGABYTE -> MEBIBYTE<br />
and looking at code now I would say it uses base 10 SI now not IEC <ac:emoticon ac:name="wink" /><br />
well actually it would be useful to have three state ('traditional', 'si', 'iec')<br />
and have $norm parameter instead of $iec taking one of these strings.</p>
<p>traditional <ac:link><ri:page ri:content-title="KILOBYTE..." /></ac:link> would mean base 2 and KB (^10), MB (^20), GB (^30)| si <ac:link><ri:page ri:content-title="KILOBYTE_SI..." /></ac:link> meaning base 10 and KB (^3) MB | iec <ac:link><ri:page ri:content-title="KIBIBYTE..." /></ac:link> meaning base 2 KiB (^10) MiB (^20) and GiB (^30)</p>
<p>and also I would like to see is_string($fileSize) -> stat FS and get info out of there</p>
Jul 01, 2008
Martin Hujer
<p>I have been busy recently, so I have updated code today. Now, you can choose which norm to use. I will update proposal to reflect changes in code and tests.</p>
Jul 03, 2008
Pawel Przeradowski
<p>Looks nice, but what about possibility of passing a string as first parameter that would be interpreted as file path to read file size from file system?</p>
<p>This could be sth like</p>
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
if(is_string($fileSize))
{
if(!file_exists($fileSize))
$fileSize = filesize($fileSize);
}
]]></ac:plain-text-body></ac:macro>
Jul 03, 2008
Martin Hujer
<p>Thanks.</p>
<p>I think, that this would break layer separation (e.g. I use this helper to format filesize loaded through ftp connection in one project).</p>
<p>But it is not very big problem to add this functionality. </p>
Jul 16, 2008
Thomas Weidner
<p>Within your code you use Zend_Measure_Binary.<br />
Nice to see that my component is reused <ac:emoticon ac:name="smile" /><br />
But you miss some things:</p>
<p>1.) When you use a other component you must also write this within your proposal, section 4 dependencies.</p>
<p>2.) Zend_Measure_Binary allows also to use localized input. Which means it would recognise "1,000.00" in german as "1 000,00" in french or "1.000,00" in english. You should also support this possibility when using Zend_Measure. Therefor you must integrate a locale (getLocale/setLocale) or/and use a generalised Zend_Locale instance from registry when available. This way all components which are localizable use the same locale.</p>
<p>3.) Zend_Measure_Binary COULD convert from/to for you. You stated that this component will not do this within your initial description. The possibility is available through Zend_Measure_Binary.</p>
<p>Greetings<br />
Thomas</p>
Aug 01, 2008
Martin Hujer
<p>Thomas, thank you!</p>
<p>1.) I've forgotten to update proposal after code changes -> updated</p>
<p>2.) Localized input added in SVN</p>
<p>3.) proposal updated</p>
Aug 01, 2008
fc
<p>Looking at the bigger picture, I have to say that you are using to many dependencies.</p>
Aug 01, 2008
Thomas Weidner
<p>Which bigger picture?</p>
<p>There's nothing bad with dependencies. They only have to be listet. The complexer a functionallity is, the more dependencies you will probably have.</p>
<p>The question is also if you would have to listen sub-dependencies.<br />
Because Zend_Measure_Binary uses itself Zend_Locale_Format and Zend_Locale and Zend_Registry.<br />
And Zend_Exception is used by Zend_View_Exception.</p>
<p>I don't really see a problem with this.</p>
Aug 12, 2008
Martin Hujer
<p>I have refactored it not to use any Locale component except Zend_Measure_Binary, which is essentially important</p>
Oct 15, 2008
Ben Scholzen
<p>You should be able to define a locale as last parameter as well, so that the output number is formatted according to that locale (and if not given the default locale is used). Also it would be nice to have a feature similar to some other formatters:</p>
<p>When you have 999,999 bytes, it results in 999.000 KB, but for 1,000,000 bytes, it should go to the next unit and display 0,9765625 MB. I'd say to make this an additional feature and not the default. This simply makes it easier for the actual application user to read.</p>
Oct 31, 2008
Ralph Schindler
<ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Official Response</ac:parameter><ac:rich-text-body>
<p>This has been accepted to Zend Laboratory.</p>
<p>There are few concerns we would like to see worked out:</p>
<ul>
<li>Currently, there is a hidden dependency on Zend_Locale. By using Zend_Measure,<br />
Zend_Locale is included into the mix, thus, by using this seemingly simple view helper,<br />
one would be building out a Zend_Locale environment automagically which could cause some<br />
performance degradation in applications. Ideally, using Zend_Measure and Zend_Locale would be<br />
an opt-in feature to keep this lightweight.</li>
</ul>
</ac:rich-text-body></ac:macro>
Dec 08, 2008
Martin Hujer
<p>Hello!</p>
<p>This component was originally designed to work without Zend_Locale, but according to the comments, I've refactored it to use it.</p>
<p>But there is no problem to cut the Zend_Locale out.</p>
<p>I think that leaving Zend_Locale as an opt-in feature is nonsense, while all functionality should work the same way without it.</p>
Mar 11, 2009
Dmitry Pereslegin
<p>Great!</p>
<p>And is there a way to automatically determine the iec or si, based on Zend_Locale. <br />
Where can I learn this information? <br />
Could it be a part of this component?</p>
Jul 14, 2009
Marc Bennewitz (private)
<p>Why the name is fileSize if it doesn't get the size of a file.<br />
This component only format binary sizes.</p>
<p>I think it would better to rename this component to Zend_View_Helper_FormatBinary or Zend_View_Helper_FormatBytes</p>
Aug 03, 2010
Martin Hujer
<p>Archived.</p>
Aug 03, 2010
Dolf Schimmel (Freeaqingme)
<p>Can I ask you why you archived it, I think it's a really useful component.</p>
Aug 17, 2010
Martin Hujer
<p>(discussed on IRC) I didn't get an answer for almost two years, so I thought I won't finish it until end of August. But with you as a Liaison I think it's possible <ac:emoticon ac:name="smile" /> But I want to finish Zend_ShortUrl first (and then I'll un-archive it)</p>