Example #1
0
function create_git_object_hash( $p_file ) {
	$t_hash_context = hash_init( 'sha1' );
	hash_update( $t_hash_context, 'blob ' . filesize( $p_file ) . "\x00" );
	hash_update_file( $t_hash_context, $p_file );
	$t_object_hash = hash_final( $t_hash_context );
	return $t_object_hash;
}
Example #2
0
 public function addFile($filename)
 {
     if (!isset($this->_hashFinal)) {
         if (is_file($filename)) {
             hash_update_file($this->getHashContext(), $filename);
             $this->addLastModified(filemtime($filename));
         }
     }
 }
Example #3
0
function get_data_sha1()
{
    global $__status, $__config;
    $context = hash_init('sha1');
    chdir($__config['blog_data_dir']);
    foreach (glob("*.blog") as $filename) {
        hash_update_file($context, $filename);
    }
    chdir($__config['blog_base_dir']);
    return hash_final($context);
}
Example #4
0
 /**
  * Adds the given file to the hash pool. The hash will be calculated over the total hash pool.
  * @param \System\IO\File The file to include in the hashing
  */
 public final function addFile(\System\IO\File $file)
 {
     if ($this->hash) {
         if ($file->exists()) {
             hash_update_file($this->hash, $file->getFullPath());
         } else {
             throw new \System\Error\Exception\FileNotFoundException('The given file does not exists: ' . $file->getFilename());
         }
     } else {
         throw new \System\Error\Exception\InvalidMethodException('This method is called after finalizing the hash');
     }
 }
Example #5
0
File: Hash.php Project: mleko/hash
 /**
  * @param string $filename
  * @param resource|null $context Stream context
  * @return bool
  */
 public function updateFile($filename, $context = null)
 {
     $hash = @hash_update_file($this->context, $filename, $context);
     if (false === $hash) {
         throw new HashException();
     }
     return $hash;
 }
 /**
  * Pump data into an active hashing context
  * from a file. Returns TRUE on success or
  * FALSE on failure.
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
  *
  * @param resource
  * @param string
  * @param resource
  * @return bool
  */
 public function updateFile($hcontext, $filename, $scontext = null)
 {
     if (!is_resource($hcontext)) {
         return false;
     }
     return hash_update_file($hcontext, $filename, $scontext);
 }
Example #7
0
 /**
  * A quick wrapper for a streamable implementation of md5.
  *
  * @param string|resource $source
  * @return string
  */
 private function md5($source)
 {
     $ctx = hash_init('md5');
     if (is_resource($source)) {
         hash_update_stream($ctx, $source);
         rewind($source);
     } else {
         hash_update_file($ctx, $source);
     }
     return hash_final($ctx);
 }
function big_file_md5($fileArray)
{
    $ctx = hash_init('md5');
    foreach ($fileArray as $fileArr) {
        hash_update_file($ctx, $fileArr[0]);
    }
    return hash_final($ctx);
}
Example #9
0
 /**
  * @param string $fileName
  */
 public function pushFile(string $fileName)
 {
     $result = hash_update_file($this->getHandle(), $fileName);
     if (!$result) {
         throw new RuntimeException();
     }
 }
Example #10
0
 /**
  * Computes more of the hash from a file.
  *
  * @param  string $dataFp The path to the source file.
  *
  * @return void
  */
 public function computeMoreFromFile($dataFp)
 {
     assert('is_cstring($dataFp)', vs(isset($this), get_defined_vars()));
     $dataFp = CFilePath::frameworkPath($dataFp);
     hash_update_file($this->m_hashingContext, $dataFp);
 }
Example #11
0
 static function get_checksum_directorio($directorio)
 {
     $checksum = null;
     $archivos = self::buscar_archivos_directorio_recursivo($directorio);
     if (!empty($archivos)) {
         $hsh_handler = hash_init('sha256');
         $sin_error = true;
         foreach ($archivos as $archivo) {
             $sin_error = @hash_update_file($hsh_handler, $archivo);
             if (!$sin_error) {
                 //Si se produce error en el calculo aborto
                 hash_final($hsh_handler);
                 toba::logger()->error("\nError calculando checksum con el archivo '{$archivo}' ");
                 throw new toba_error("\nError calculando checksum con el archivo '{$archivo}' ");
             }
         }
         $checksum = hash_final($hsh_handler);
     }
     return $checksum;
 }