ParagonIE\Halite\Contract\StreamInterface::getSize PHP Method

getSize() public method

How big is this buffer?
public getSize ( ) : integer
return integer
    public function getSize() : int;

Usage Example

Example #1
0
 /**
  * 
  * @param \ParagonIE\Halite\Contract\StreamInterface $fileStream
  * @param AuthenticationKey $key
  * @param type $raw
  * @return type
  */
 public static function checksumStream(StreamInterface $fileStream, KeyInterface $key = null, $raw = false)
 {
     $config = self::getConfig(Halite::HALITE_VERSION_FILE, 'checksum');
     if ($key) {
         if (!$key instanceof AuthenticationKey) {
             throw new \ParagonIE\Halite\Alerts\InvalidKey('Argument 2: Expected an instance of AuthenticationKey');
         }
         $state = \Sodium\crypto_generichash_init($key->get(), $config->HASH_LEN);
     } else {
         $state = \Sodium\crypto_generichash_init(null, $config->HASH_LEN);
     }
     $size = $fileStream->getSize();
     while ($fileStream->remainingBytes() > 0) {
         $read = $fileStream->readBytes($fileStream->getPos() + $config->BUFFER > $size ? $size - $fileStream->getPos() : $config->BUFFER);
         \Sodium\crypto_generichash_update($state, $read);
     }
     if ($raw) {
         return \Sodium\crypto_generichash_final($state, $config->HASH_LEN);
     }
     return \Sodium\bin2hex(\Sodium\crypto_generichash_final($state, $config->HASH_LEN));
 }