Truncates a file to a given length

@param   int  $size length to truncate file to
@return  bool
337528
public function truncate(int $size): bool
    {
        $this->size = $size;
        foreach (array_filter(array_keys($this->content),
                              function($pos) use ($size)
                              {
                                  return $pos >= $size;
                              }
                ) as $removePos) {
            unset($this->content[$removePos]);
        }

        return true;
    }
188899
public function fileSize($size, $decimals = 2)
    {

        switch (true)
        {
            case $size >= ((1 << 50) * 10):
                $postfix = 'PB';
                $size /= (1 << 50);
                break;

            case $size >= ((1 << 40) * 10):
                $postfix = 'TB';
                $size /= (1 << 40);
                break;

            case $size >= ((1 << 30) * 10):
                $postfix = 'GB';
                $size /= (1 << 30);
                break;

            case $size >= ((1 << 20) * 10):
                $postfix = 'MB';
                $size /= (1 << 20);
                break;

            case $size >= ((1 << 10) * 10):
                $postfix = 'KB';
                $size /= (1 << 10);
                break;

            default:
                $postfix = 'B';
        }

        return \round($size, $decimals) . ' ' . $postfix;
    }
934746
private function calculateSizeOfRemainingLengthField(int $size): int
    {
        $blockSize = $iterations = 0;
        while ($size >= $blockSize) {
            $iterations++;
            $blockSize = 128 ** $iterations;
        }

        $this->sizeOfRemainingLengthField = $iterations;
        return $iterations;
    }
1360522
public function cleanup($size, $rate)
    {
        // Check if cache size exceeds cache limit
        if (($cacheSize = (int) file_get_contents($this->storage)) <= $size) {
            return false;
        }

        // Cache size exceeds limit, so we build a sorted list of all files in
        // the cache - may take quite some time.
        clearstatcache();
        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($this->root, \RecursiveDirectoryIterator::CURRENT_AS_FILEINFO)
        );

        $ctimes   = array();
        $filedata = array();
        foreach ($iterator as $file) {
            if ($file->isFile() &&
                 ($file->getFilename() !== basename($this->storage)))
            {
                $ctimes[]   = $file->getCTime();
                $filedata[] = array(realpath($file->getPathname()), $file->getSize());
            }
        }

        // Sort the file data depending on the ctimes
        array_multisort(
            $ctimes, SORT_NUMERIC, SORT_ASC,
            $filedata
        );

        // Remove files until we reached the maximum cache size
        $maxSize = $size * $rate;
        $reduced = 0;
        foreach ($filedata as $file) {
            $reduced += $file[1];
            unlink($file[0]);

            // Abort deletion loop, if we reached the lower border
            if (($cacheSize - $reduced) < $maxSize) {
                break;
            }
        }

        // Write new cache size to storage file
        file_put_contents($this->storage, file_get_contents($this->storage) - $reduced);
    }
1372646
public function iniHumanFriendlySize($size){

        switch( substr($size,-1) ) {
            case 'G':
                $size = $size * 1024;
            case 'M':
                $size = $size * 1024;
            case 'K':
                $size = $size * 1024;
        }//switch

        return $this->humanFileSize($size);

    }
343546
protected function updateSize($size) {
		$size = sprintf('%' . self::SHM_DATA_OFFSET . 'd', intval($size));
		return !!$this->write(0, $size);
	}
244553
public void truncate(int size) {

        m_buffer.truncate(size);
        m_position = Math.min(size, m_position);
    }
1083932
public function size($file, int $size): bool
    {
        if (empty($filename = $this->resolveFilename($file))) {
            return false;
        }

        return $this->files->size($filename) <= ($size * 1024);
    }
961828
public function truncate($table = '')
    {
        // if table name not pass
        if (!empty($table)) {
            // create count query
            $this->sql = "TRUNCATE TABLE `$table`;";
            // pdo prepare statement
            $this->STH = $this->prepare($this->sql);

            try {
                if ($this->STH->execute()) {
                    // close pdo
                    $this->STH->closeCursor();
                    // return number of count
                    return true;
                } else {
                    self::error($this->STH->errorInfo());
                }
            } catch (\PDOException $e) {
                // get pdo error and pass on error method
                self::error($e->getMessage() . ': ' . __LINE__);
            }
        } else {
            self::error('Table name not found..');
        }
    }
1250132
public function fitsInto(Size $size)
    {
        return ($this->width <= $size->width) && ($this->height <= $size->height);
    }
1102686
function getsize($size)
    {
        $last = strtolower($size{strlen($size) - 1});
        switch ($last) {
            case 'g':
                $size *= 1024;
            case 'm':
                $size *= 1024;
            case 'k':
                $size *= 1024;
        }

        return $size;
    }
118168
public static function getImageSize( string $size = 'thumbnail') {
		$sizes = self::getImageSizes();
		$size  = key_exists( $size, $sizes ) ? $size : 'thumbnail';

		return $sizes[ $size ];
	}
697459
public static function formatFileSize($size) {
        if ( $size/1024 < 1 ) {
            return $size ." B";
        } else if ( $size/1024 > 1 && $size/(1024*1024) < 1 ) {
            return number_format($size/1024, 2, '.', '') .'KB';
        } else if ( $size/(1024*1024) > 1 && $size/(1024*1024*1024)< 1 ) {
            return number_format($size/(1024*1024), 2, '.', '') ." MB";
        } else {
            return number_format($size/(1024*1024*1024), 2, '.', '')." GB";
        }
    }
1368700
public function stream_truncate($aSize)
    {
        if (strlen(self::$string[$this->path]) > $aSize) {
            self::$string[$this->path] = substr(self::$string[$this->path], 0, $aSize);
        } else if (strlen(self::$string[$this->path]) < $aSize) {
            self::$string[$this->path] = str_pad(self::$string[$this->path], $aSize, "\0", STR_PAD_RIGHT);
        }
        return true;
    }
1311613
public function truncate($length)
    {
        $this->_text = StringHelper::truncate($this->_text, $length);
        
        return $this;
    }
1194636
public function subtract(Size $size): Size
    {
        $result = $this->bit - $size->get('b');

        if (0 > $result) {
            throw new \OutOfBoundsException('Could not subtract, the result would be less than 0.');
        }

        $this->bit = $result;

        return $this;
    }
52042
public function formatFilesize($size)
        {
            $kb = 1024;
            $mb = 1048576;
            $gb = 1073741824;
            $tb = 1099511627776;

            if ($size < $kb) {
                return $size . " B";
            } else if ($size < $mb) {
                return round($size / $kb, 2) . " KB";
            } else if ($size < $gb) {
                return round($size / $mb, 2) . " MB";
            } else if ($size < $tb) {
                return round($size / $gb, 2) . " GB";
            } else {
                return round($size / $tb, 2) . " TB";
            }
        }