Validate that a resource stream start with the provided partial hash
@param resource $stream
@param string $partialHash
@return bool
341568
private function validateStreamHash($stream, $partialHash)
    {
        $fullHash = $this->getStreamSHA1($stream);
        return $this->validateHash($fullHash, $partialHash);
    }
1024034
public static function createFromResource($resource): Stream
    {
        if (!\is_resource($resource))
        {
            throw new \InvalidArgumentException('Stream must be a resource');
        }

        $obj           = new self();
        $obj->stream   = $resource;
        $meta          = stream_get_meta_data($obj->stream);
        $obj->seekable = $meta['seekable'];
        $obj->readable = isset(self::$readWriteHash['read'][$meta['mode']]);
        $obj->writable = isset(self::$readWriteHash['write'][$meta['mode']]);
        $obj->uri      = $obj->getMetadata('uri');

        return $obj;
    }
1008302
private function validateHash($firstHash, $secondHash)
    {
        // Empty hash will always return false, because they are no validatable
        if (empty($firstHash) || empty($secondHash)) {
            throw new InvalidArgumentException('FlysystemAssetStore::validateHash can not validate empty hashes');
        }
        // Return true if $firstHash start with $secondHash or if $secondHash starts with $firstHash
        return
            strpos($firstHash, $secondHash) === 0 ||
            strpos($secondHash, $firstHash) === 0;
    }
1153171
public function hasHtmlOutput()
    {
        if ($this->currentUser->getUserId() == \Gems_User_UserLoader::SYSTEM_USER_ID) {
            $this->addMessage($this->getNotAllowedMessage());
            return false;
        }

        return parent::hasHtmlOutput();
    }
830462
public function getLimitedContentStream(StreamInterface $stream, PartBuilder $part)
    {
        $length = $part->getStreamContentLength();
        if ($length !== 0) {
            return $this->newLimitStream(
                $stream,
                $part->getStreamContentLength(),
                $part->getStreamContentStartOffset()
            );
        }
        return null;
    }
220068
public function validateHash($sRef, $sGuid, $sHash)
    {
        return isAdmin() || $this->generateHash($sRef, $sGuid) === $sHash;
    }
615545
private function matchesHash($hash, \DateTime $date)
    {
        $ordinals = array(
            '1' => 'first',
            '2' => 'second',
            '3' => 'third',
            '4' => 'fourth',
            '5' => 'fifth'
        );
        $hashParts = explode('#', $hash);

        if ($hashParts[0] != $this->getFieldValueFromDate($date)) {
            return false;
        }

        return $this->matchesRelativeDate($date, $ordinals[$hashParts[1]]);
    }
613353
def validate_partial_uploads!(part_uids)
      input = Queue.new
      part_uids.each { |part_uid| input << part_uid }
      input.close

      results = Queue.new

      thread_count   = storage.concurrency[:concatenation] if storage.respond_to?(:concurrency)
      thread_count ||= 10

      threads = thread_count.times.map do
        Thread.new do
          begin
            loop do
              part_uid = input.pop or break
              part_info = storage.read_info(part_uid)
              results << Tus::Info.new(part_info)
            end
            nil
          rescue => error
            input.clear
            error
          end
        end
      end

      errors = threads.map(&:value).compact

      if errors.any? { |error| error.is_a?(Tus::NotFound) }
        error!(400, "One or more partial uploads were not found")
      elsif errors.any?
        fail errors.first
      end

      part_infos = Array.new(results.size) { results.pop } # convert Queue into an Array

      unless part_infos.all?(&:partial?)
        error!(400, "One or more uploads were not partial")
      end

      if max_size && part_infos.map(&:length).inject(0, :+) > max_size
        error!(400, "The sum of partial upload lengths exceed Tus-Max-Size")
      end
    end
111619
public function withEtag($hash, $weak = false)
    {
        return $this->withHeader('Etag', sprintf('%s"%s"', ($weak) ? 'W/' : null, $hash));
    }
503142
public function setStream($stream = null)
    {
        // String passed in? Try converting it to a stream
        if (is_string($stream)) {
            $stream = @fopen($stream, 'a');
        }

        // Make sure the stream is a resource
        if (!is_resource($stream)) {
            throw new \InvalidArgumentException('Invalid Stream');
        }

        // Store it
        $this->stream = $stream;

        // Afford chaining
        return $this;
    }
905619
public function addChunk(string $hash, string $chunk, ?string $context = null): bool
    {
        $path = $this->getPath($hash, $context, false);
        if (!file_exists($path)) {
            throw new NotFoundHttpException('temporary file not found');
        }

        $file = fopen($path, "a");
        $result = fwrite($file, $chunk);

        fflush($file);
        fclose($file);

        if ($result === false || $result != strlen($chunk)) {
            return false;
        }

        return true;
    }
497523
private function findHashOf(FileIDHelper $helper, ParsedFileID $parsedFileID, Filesystem $filesystem)
    {
        // Re build the file ID but without the variant
        $fileID = $helper->buildFileID(
            $parsedFileID->getFilename(),
            $parsedFileID->getHash()
        );

        // Couldn't find the original file, let's bail.
        if (!$filesystem->has($fileID)) {
            return false;
        }

        // Get hash from stream
        $stream = $filesystem->readStream($fileID);
        $hc = hash_init('sha1');
        hash_update_stream($hc, $stream);
        $fullHash = hash_final($hc);

        return $fullHash;
    }
930992
public function getLimitedPartStream(StreamInterface $stream, PartBuilder $part)
    {
        return $this->newLimitStream(
            $stream,
            $part->getStreamPartLength(),
            $part->getStreamPartStartOffset()
        );
    }
1305430
private function newLimitStream(StreamInterface $stream, $length, $start)
    {
        return new SeekingLimitStream(
            $this->newNonClosingStream($stream),
            $length,
            $start
        );
    }
924159
private function mergeStream($string, $stream)
    {
        rewind($stream);
        $regex = sprintf('/(%s)/', implode('|', $this->hash));
        preg_match_all($regex, $string, $match, PREG_SET_ORDER);
        $list = $this->collect($match);
        $bodies = preg_split($regex, $string);
        foreach ($bodies as $body) {
            fwrite($stream, $body);
            $index = array_shift($list);
            if (isset($this->streams[$index])) {
                $popStream = $this->streams[$index];
                rewind($popStream);
                stream_copy_to_stream($popStream, $stream);
            }
        }

        return $stream;
    }
973135
private function validate($hash, string $validation_regex): void {
    if(!is_string($hash) || preg_match($validation_regex, $hash) === 0) {
      throw new InvalidArgumentException('Expected hash, but got ' . var_export($hash, true) . '] instead');
    }
  }
1014890
public function createCacheFile(string $hash, string $fileName, ?string $context = null): bool
    {
        foreach ($this->cacheAdapters as $cacheAdapter) {
            if ($cacheAdapter->create($hash, $fileName, $context)) {
                return true;
            }
        }

        return false;
    }