Example #1
0
 public function isEqualTo($query)
 {
     if (!$query instanceof self) {
         $query = new self($query);
     }
     return $this->hash === $query->getHash();
 }
Example #2
0
 /**
  * Create a tree hash from a content body
  *
  * @param string|resource|EntityBody $content   Content to create a tree hash for
  * @param string                     $algorithm A valid hash algorithm name as returned by `hash_algos()`
  *
  * @return TreeHash
  */
 public static function fromContent($content, $algorithm = self::DEFAULT_ALGORITHM)
 {
     $treeHash = new self($algorithm);
     // Read the data in 1MB chunks and add to tree hash
     $content = EntityBody::factory($content);
     while ($data = $content->read(Size::MB)) {
         $treeHash->addData($data);
     }
     // Pre-calculate hash
     $treeHash->getHash();
     return $treeHash;
 }