Skip to end of metadata
Go to start of metadata

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

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

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

    Some of my thoughts on this

    • I think it could take third parameter $iec like

      When $iec is true this would produce KiB instead of KB, MiB instead of MB and so on.
      These are IEC standard binary prefixes that were introduced to prevent confusion with SI prefixes.
      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.

    For further information please see http://en.wikipedia.org/wiki/Binary_prefix#IEC_standard_prefixes.

    • 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
      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
    1. May 12, 2008

      Hi, thank you for your comment. These enhancements would be really userful. I will implement them after Zend comments on this helper

    2. May 24, 2008

      I've updated code to allow SI units, but the Zend_Measure_Binary says, that unit of KILOBYTE_SI (=1000) is 'kB.' not 'KiB'

      1. Jul 14, 2009

        In Zend_Measure the differences to SI is detected by type.
        I think it can be assumed to this helper and the $iec parameter is no longer needed or if I wrong ?

  2. May 14, 2008

    This is a much needed addition IMO.

    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.

    1. May 24, 2008

      Hi.

      I've updated proposal and code to do that

  3. May 23, 2008

    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.

    1. May 24, 2008

      Hi.

      I've refactored code to use Zend_Measure_Binary.

  4. May 24, 2008

    Marthin, Zend_Measure_Binary has corresponding bi IEC suffixes
    eg MEGABYTE -> MEBIBYTE
    and looking at code now I would say it uses base 10 SI now not IEC
    well actually it would be useful to have three state ('traditional', 'si', 'iec')
    and have $norm parameter instead of $iec taking one of these strings.

    traditional [KILOBYTE...] would mean base 2 and KB (^10), MB (^20), GB (^30)| si [KILOBYTE_SI...] meaning base 10 and KB (^3) MB | iec [KIBIBYTE...] meaning base 2 KiB (^10) MiB (^20) and GiB (^30)

    and also I would like to see is_string($fileSize) -> stat FS and get info out of there

    1. Jul 01, 2008

      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.

  5. Jul 03, 2008

    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?

    This could be sth like

    1. Jul 03, 2008

      Thanks.

      I think, that this would break layer separation (e.g. I use this helper to format filesize loaded through ftp connection in one project).

      But it is not very big problem to add this functionality.

  6. Jul 16, 2008

    Within your code you use Zend_Measure_Binary.
    Nice to see that my component is reused
    But you miss some things:

    1.) When you use a other component you must also write this within your proposal, section 4 dependencies.

    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.

    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.

    Greetings
    Thomas

    1. Aug 01, 2008

      Thomas, thank you!

      1.) I've forgotten to update proposal after code changes -> updated

      2.) Localized input added in SVN

      3.) proposal updated

      1. Aug 01, 2008

        fc

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

        1. Aug 01, 2008

          Which bigger picture?

          There's nothing bad with dependencies. They only have to be listet. The complexer a functionallity is, the more dependencies you will probably have.

          The question is also if you would have to listen sub-dependencies.
          Because Zend_Measure_Binary uses itself Zend_Locale_Format and Zend_Locale and Zend_Registry.
          And Zend_Exception is used by Zend_View_Exception.

          I don't really see a problem with this.

  7. Aug 12, 2008

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

    1. Oct 15, 2008

      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:

      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.

  8. Oct 31, 2008

    Zend Official Response
    This has been accepted to Zend Laboratory.

    There are few concerns we would like to see worked out:

    • Currently, there is a hidden dependency on Zend_Locale. By using Zend_Measure,
      Zend_Locale is included into the mix, thus, by using this seemingly simple view helper,
      one would be building out a Zend_Locale environment automagically which could cause some
      performance degradation in applications. Ideally, using Zend_Measure and Zend_Locale would be
      an opt-in feature to keep this lightweight.
    1. Dec 08, 2008

      Hello!

      This component was originally designed to work without Zend_Locale, but according to the comments, I've refactored it to use it.

      But there is no problem to cut the Zend_Locale out.

      I think that leaving Zend_Locale as an opt-in feature is nonsense, while all functionality should work the same way without it.

  9. Mar 11, 2009

    Great!

    And is there a way to automatically determine the iec or si, based on Zend_Locale.
    Where can I learn this information?
    Could it be a part of this component?

  10. Jul 14, 2009

    Why the name is fileSize if it doesn't get the size of a file.
    This component only format binary sizes.

    I think it would better to rename this component to Zend_View_Helper_FormatBinary or Zend_View_Helper_FormatBytes

  11. Aug 03, 2010

    Archived.

    1. Aug 03, 2010

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

      1. Aug 17, 2010

        (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 But I want to finish Zend_ShortUrl first (and then I'll un-archive it)