Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_View_Helper_FileSize Component Proposal

Proposed Component Name Zend_View_Helper_FileSize
Developer Notes http://framework.zend.com/wiki/display/ZFDEV/Zend_View_Helper_FileSize
Proposers Martin Hujer
Zend Liaison Dolf Schimmel (Freeaqingme)
Revision 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)

Table of Contents

1. Overview

Zend_View_Helper_FileSize is a simple helper that formats any filesize in bytes to human readable string.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • This helper will correctly formats any filesize in bytes to human readable string.

4. Dependencies on Other Framework Components

  • Zend_Exception
  • Zend_Registry (optional
  • Zend_Locale (optional)
  • Zend_Locale_Format (optional)
  • Zend_Measure_Binary
  • Zend_View_Exception

5. Theory of Operation

...

6. Milestones / Tasks

  • Milestone 1: Community and Zend review

7. Class Index

  • Zend_View_Helper_FileSize

8. Use Cases

UC-01
UC-02 - set export units
UC-03 - set the norm

9. Class Skeletons

]]></ac:plain-text-body></ac:macro>

]]></ac:plain-text-body></ac:macro>

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. May 05, 2008

    <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>

    1. May 12, 2008

      <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>

    2. May 24, 2008

      <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>

      1. Jul 14, 2009

        <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>

  2. May 14, 2008

    <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>

    1. May 24, 2008

      <p>Hi.</p>

      <p>I've updated proposal and code to do that <ac:emoticon ac:name="smile" /></p>

  3. May 23, 2008

    <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>

    1. May 24, 2008

      <p>Hi.</p>

      <p>I've refactored code to use Zend_Measure_Binary.</p>

  4. May 24, 2008

    <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>

    1. Jul 01, 2008

      <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>

  5. Jul 03, 2008

    <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))

    Unknown macro: { //throw exception }

    $fileSize = filesize($fileSize);
    }
    ]]></ac:plain-text-body></ac:macro>

    1. Jul 03, 2008

      <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>

  6. Jul 16, 2008

    <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>

    1. Aug 01, 2008

      <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>

      1. Aug 01, 2008

        fc

        <p>Looking at the bigger picture, I have to say that you are using to many dependencies.</p>

        1. Aug 01, 2008

          <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>

  7. Aug 12, 2008

    <p>I have refactored it not to use any Locale component except Zend_Measure_Binary, which is essentially important</p>

    1. Oct 15, 2008

      <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>

  8. Oct 31, 2008

    <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>

    1. Dec 08, 2008

      <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>

  9. Mar 11, 2009

    <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>

  10. Jul 14, 2009

    <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>

  11. Aug 03, 2010

    <p>Archived.</p>

    1. Aug 03, 2010

      <p>Can I ask you why you archived it, I think it's a really useful component.</p>

      1. Aug 17, 2010

        <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>