root

Changeset 732

Show
Ignore:
Timestamp:
11/14/09 10:16:10 (4 months ago)
Author:
wbond
Message:

Fixed ticket #336 - Updated fFilesystem::convertToBytes() to properly handle integers without a suffix and sizes with fractions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fFilesystem.php

    r696 r732 Hide Line Numbers
    33 * Handles filesystem-level tasks including filesystem transactions and the reference map to keep all fFile and fDirectory objects in sync 
    44 *  
    5  * @copyright  Copyright (c) 2008-2009 Will Bond 
     5 * @copyright  Copyright (c) 2008-2009 Will Bond, others 
    66 * @author     Will Bond [wb] <will@flourishlib.com> 
     7 * @author     Alex Leeds [al] <alex@kingleeds.com> 
    78 * @license    http://flourishlib.com/license 
    89 *  
     
    1011 * @link       http://flourishlib.com/fFilesystem 
    1112 *  
    12  * @version    1.0.0b11 
     13 * @version    1.0.0b12 
     14 * @changes    1.0.0b12  Updated ::convertToBytes() to properly handle integers without a suffix and sizes with fractions [al+wb, 2009-11-14] 
    1315 * @changes    1.0.0b11  Corrected the API documentation for ::getPathInfo() [wb, 2009-09-09] 
    1416 * @changes    1.0.0b10  Updated ::updateExceptionMap() to not contain the Exception class parameter hint, allowing NULL to be passed [wb, 2009-08-20] 
     
    167169     * Takes a file size including a unit of measure (i.e. kb, GB, M) and converts it to bytes 
    168170     *  
     171     * Sizes are interpreted using base 2, not base 10. Sizes above 2GB may not 
     172     * be accurately represented on 32 bit operating systems. 
     173     *  
    169174     * @param  string $size  The size to convert to bytes 
    170175     * @return integer  The number of bytes represented by the size 
     
    172177    static public function convertToBytes($size) 
    173178    { 
    174         if (!preg_match('#^(\d+)\s*(k|m|g|t)?(ilo|ega|era|iga)?( )?b?(yte(s)?)?$#D', strtolower(trim($size)), $matches)) { 
     179        if (!preg_match('#^(\d+(?:\.\d+)?)\s*(k|m|g|t)?(ilo|ega|era|iga)?( )?b?(yte(s)?)?$#D', strtolower(trim($size)), $matches)) { 
    175180            throw new fProgrammerException( 
    176181                'The size specified, %s, does not appears to be a valid size', 
     
    179184        } 
    180185         
    181         if ($matches[2] == '') { 
     186        if (empty($matches[2])) { 
    182187            $matches[2] = 'b'; 
    183188        } 
     
    188193                          'g' => 1073741824, 
    189194                          't' => 1099511627776); 
    190         return $matches[1] * $size_map[$matches[2]]
     195        return round($matches[1] * $size_map[$matches[2]])
    191196    } 
    192197     
     
    663668 
    664669/** 
    665  * Copyright (c) 2008-2009 Will Bond <will@flourishlib.com> 
     670 * Copyright (c) 2008-2009 Will Bond <will@flourishlib.com>, others 
    666671 *  
    667672 * Permission is hereby granted, free of charge, to any person obtaining a copy