当前位置: 首页>>代码示例>>PHP>>正文


PHP hash_update_stream函数代码示例

本文整理汇总了PHP中hash_update_stream函数的典型用法代码示例。如果您正苦于以下问题:PHP hash_update_stream函数的具体用法?PHP hash_update_stream怎么用?PHP hash_update_stream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了hash_update_stream函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateStream

 public function updateStream($handle)
 {
     if ($this->ctx === null) {
         $this->ctx = hash_init($this->algo);
     }
     hash_update_stream($this->ctx, $handle);
     return $this;
 }
开发者ID:Ronmi,项目名称:fruit-cryptokit,代码行数:8,代码来源:Hash.php

示例2: hash

 /**
  * @param $resource
  *
  * @return string
  */
 public function hash($resource)
 {
     rewind($resource);
     $context = hash_init($this->algo);
     hash_update_stream($context, $resource);
     fclose($resource);
     return hash_final($context);
 }
开发者ID:laerciobernardo,项目名称:CodeDelivery,代码行数:13,代码来源:StreamHasher.php

示例3: getFileHash

 public function getFileHash($path)
 {
     $stream = $this->filesystem->readStream($path);
     if ($stream !== false) {
         $context = hash_init(self::HASH_ALGORITHM);
         hash_update_stream($context, $stream);
         return hash_final($context);
     }
     return false;
 }
开发者ID:kivagant,项目名称:staticus-core,代码行数:10,代码来源:DestroyEqualResourceCommand.php

示例4: md5FromStream

 /**
  * @param resource $fp The opened file
  * @param number $offset The offset.
  * @param number $length Maximum number of characters to copy from
  *   $fp into the hashing context.
  * @param boolean $raw_output When TRUE, returns the digest in raw
  *   binary format with a length of 16
  *
  * @return string
  */
 public static function md5FromStream($fp, $offset = 0, $length = -1)
 {
     $pos = ftell($fp);
     $ctx = hash_init('md5');
     fseek($fp, $offset, SEEK_SET);
     hash_update_stream($ctx, $fp, $length);
     if ($pos !== false) {
         fseek($fp, $pos, SEEK_SET);
     }
     return hash_final($ctx, true);
 }
开发者ID:baidubce,项目名称:bce-sdk-php,代码行数:21,代码来源:HashUtils.php

示例5: md5FromStream

 /**
  * @param resource $fp The opened file
  * @param number $offset The offset.
  * @param number $length Maximum number of characters to copy from
  *   $fp into the hashing context.
  * @param boolean $raw_output When TRUE, returns the digest in raw
  *   binary format with a length of 16
  *
  * @return string
  */
 static function md5FromStream($fp, $offset = 0, $length = -1, $raw_output = false)
 {
     $pos = ftell($fp);
     $ctx = hash_init('md5');
     fseek($fp, $offset, SEEK_SET);
     hash_update_stream($ctx, $fp, $length);
     // TODO(leeight) restore ftell value?
     if ($pos !== false) {
         fseek($fp, $pos, SEEK_SET);
     }
     return hash_final($ctx, $raw_output);
 }
开发者ID:tanxiniao,项目名称:bce,代码行数:22,代码来源:Coder.php

示例6: handle

 /**
  * Returns hash value of given path using supplied hash algorithm
  *
  * @param string $path
  * @param string $algo any algorithm supported by hash()
  * @return string|bool
  * @see http://php.net/hash
  */
 public function handle($path, $algo = 'sha256')
 {
     if (!in_array($algo, hash_algos())) {
         throw new \InvalidArgumentException('Hash algorithm ' . $algo . ' is not supported');
     }
     $stream = $this->filesystem->readStream($path);
     if ($stream === false) {
         return false;
     }
     $hc = hash_init($algo);
     hash_update_stream($hc, $stream);
     return hash_final($hc);
 }
开发者ID:emgag,项目名称:flysystem-hash,代码行数:21,代码来源:HashPlugin.php

示例7: serve

 private function serve($path)
 {
     $stream = fopen($path, 'rb');
     $mtime = gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT';
     $stat = fstat($stream);
     $hash = hash_init('sha1');
     hash_update_stream($hash, $stream);
     hash_update($hash, $mtime);
     $etag = hash_final($hash);
     fseek($stream, 0, SEEK_SET);
     $headers = array('Content-Type', self::getContentType($path), 'Content-Length', $stat['size'], 'Last-Modified', $mtime, 'ETag', $etag);
     return array(200, $headers, $stream);
 }
开发者ID:LookForwardPersistence,项目名称:appserver-in-php,代码行数:13,代码来源:FileServe.php

示例8: serve

 private function serve($path, $req_etag, $req_lastmod)
 {
     $stream = fopen($path, 'rb');
     $mtime = gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT';
     $stat = fstat($stream);
     $hash = hash_init('sha1');
     hash_update_stream($hash, $stream);
     hash_update($hash, $mtime);
     $etag = hash_final($hash);
     if ($req_etag === $etag) {
         return array(304, array(), '');
     }
     if ($req_lastmod === $mtime) {
         return array(304, array(), '');
     }
     $headers = array('Content-Type', self::getContentType($path), 'Content-Length', $stat['size'], 'Last-Modified', $mtime, 'ETag', $etag);
     return array(200, $headers, $stream);
 }
开发者ID:piotras,项目名称:appserver-in-php,代码行数:18,代码来源:FileServe.class.php

示例9: updateStream

 /**
  * Pump data into an active hashing context
  * from an open stream. Returns the actual
  * number of bytes added to the hashing
  * context from handle.
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
  *
  * @param resource
  * @param resource
  * @param int
  * @return int
  */
 public function updateStream($context, $handle, $length = -1)
 {
     if (!is_resource($context) || !is_resource($handle)) {
         return false;
     }
     return hash_update_stream($context, $handle, $length);
 }
开发者ID:Invision70,项目名称:php-bitpay-client,代码行数:19,代码来源:HashExtension.php

示例10: md5

 /**
  * 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);
 }
开发者ID:Zn4rK,项目名称:clouddrive-php,代码行数:17,代码来源:CloudDrive.php

示例11: save

 /**
  * Save an Object into Object Storage.
  *
  * This takes an \OpenStack\ObjectStore\v1\Resource\Object
  * and stores it in the given container in the present
  * container on the remote object store.
  *
  * @param object   $obj  \OpenStack\ObjectStore\v1\Resource\Object The object to
  *                       store.
  * @param resource $file An optional file argument that, if set, will be
  *                       treated as the contents of the object.
  *
  * @return boolean true if the object was saved.
  *
  * @throws \OpenStack\Common\Transport\Exception\LengthRequiredException      if the Content-Length could not be
  *                                                                            determined and chunked encoding was
  *                                                                            not enabled. This should not occur for
  *                                                                            this class, which always automatically
  *                                                                            generates Content-Length headers.
  *                                                                            However, subclasses could generate
  *                                                                            this error.
  * @throws \OpenStack\Common\Transport\Exception\UnprocessableEntityException if the checksum passed here does not
  *                                                                            match the checksum calculated remotely.
  * @throws \OpenStack\Common\Exception                                        when an unexpected (usually
  *                                                                            network-related) error condition arises.
  */
 public function save(Object $obj, $file = null)
 {
     if (empty($this->token)) {
         throw new Exception('Container does not have an auth token.');
     }
     if (empty($this->url)) {
         throw new Exception('Container does not have a URL to send data.');
     }
     //$url = $this->url . '/' . rawurlencode($obj->name());
     $url = self::objectUrl($this->url, $obj->name());
     // See if we have any metadata.
     $headers = [];
     $md = $obj->metadata();
     if (!empty($md)) {
         $headers = self::generateMetadataHeaders($md, Container::METADATA_HEADER_PREFIX);
     }
     // Set the content type.
     $headers['Content-Type'] = $obj->contentType();
     // Add content encoding, if necessary.
     $encoding = $obj->encoding();
     if (!empty($encoding)) {
         $headers['Content-Encoding'] = rawurlencode($encoding);
     }
     // Add content disposition, if necessary.
     $disposition = $obj->disposition();
     if (!empty($disposition)) {
         $headers['Content-Disposition'] = $disposition;
     }
     // Auth token.
     $headers['X-Auth-Token'] = $this->token;
     // Add any custom headers:
     $moreHeaders = $obj->additionalHeaders();
     if (!empty($moreHeaders)) {
         $headers += $moreHeaders;
     }
     if (empty($file)) {
         // Now build up the rest of the headers:
         $headers['Etag'] = $obj->eTag();
         // If chunked, we set transfer encoding; else
         // we set the content length.
         if ($obj->isChunked()) {
             // How do we handle this? Does the underlying
             // stream wrapper pay any attention to this?
             $headers['Transfer-Encoding'] = 'chunked';
         } else {
             $headers['Content-Length'] = $obj->contentLength();
         }
         $response = $this->client->put($url, $obj->content(), ['headers' => $headers]);
     } else {
         // Rewind the file.
         rewind($file);
         // XXX: What do we do about Content-Length header?
         //$headers['Transfer-Encoding'] = 'chunked';
         $stat = fstat($file);
         $headers['Content-Length'] = $stat['size'];
         // Generate an eTag:
         $hash = hash_init('md5');
         hash_update_stream($hash, $file);
         $etag = hash_final($hash);
         $headers['Etag'] = $etag;
         // Not sure if this is necessary:
         rewind($file);
         $response = $this->client->put($url, $file, ['headers' => $headers]);
     }
     if ($response->getStatusCode() != 201) {
         throw new Exception('An unknown error occurred while saving: ' . $response->status());
     }
     return true;
 }
开发者ID:ktroach,项目名称:openstack-sdk-php,代码行数:95,代码来源:Container.php

示例12: createFileBlob

 /**
  * places contents into a file blob
  * 
  * @param  stream|string|tempFile $contents
  * @return string hash
  */
 public function createFileBlob($contents)
 {
     if (!is_resource($contents)) {
         throw new Tinebase_Exception_NotImplemented('please implement me!');
     }
     $handle = $contents;
     rewind($handle);
     $ctx = hash_init('sha1');
     hash_update_stream($ctx, $handle);
     $hash = hash_final($ctx);
     $hashDirectory = $this->_basePath . '/' . substr($hash, 0, 3);
     if (!file_exists($hashDirectory)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' create hash directory: ' . $hashDirectory);
         if (mkdir($hashDirectory, 0700) === false) {
             throw new Tinebase_Exception_UnexpectedValue('failed to create directory');
         }
     }
     $hashFile = $hashDirectory . '/' . substr($hash, 3);
     if (!file_exists($hashFile)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' create hash file: ' . $hashFile);
         rewind($handle);
         $hashHandle = fopen($hashFile, 'x');
         stream_copy_to_stream($handle, $hashHandle);
         fclose($hashHandle);
     }
     return array($hash, $hashFile);
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:33,代码来源:FileSystem.php

示例13: getHashOfStream

 /**
  * {@inheritdoc}
  */
 public function getHashOfStream(StreamInterface $stream, $binary = false)
 {
     $res = hash_init($this->alg);
     hash_update_stream($res, $stream->detach());
     return hash_final($res);
 }
开发者ID:spomky-labs,项目名称:php-http-digest,代码行数:9,代码来源:Sha512Algorithm.php

示例14: hashPiece

 /**
  * Gets SHA1 hash (binary) of a piece of a file.
  *
  * @param integer $n_piece 0 bases index of the current peice.
  * @param integer $size_piece Generic piece size of the file in bytes.
  * @return string Byte string of the SHA1 hash of this piece.
  */
 protected function hashPiece($n_piece, $size_piece)
 {
     $file_handle = $this->getReadHandle();
     $hash_handle = hash_init('sha1');
     fseek($file_handle, $n_piece * $size_piece);
     hash_update_stream($hash_handle, $file_handle, $size_piece);
     // Getting hash of the piece as raw binary.
     return hash_final($hash_handle, true);
 }
开发者ID:r15ch13,项目名称:PHPTracker,代码行数:16,代码来源:File.php

示例15: setFileContents

 public function setFileContents($file)
 {
     if (is_resource($file)) {
         $hash_ctx = hash_init('md5');
         $length = hash_update_stream($hash_ctx, $file);
         $md5 = hash_final($hash_ctx, true);
         rewind($file);
         curl_setopt($this->curl, CURLOPT_PUT, true);
         curl_setopt($this->curl, CURLOPT_INFILE, $file);
         curl_setopt($this->curl, CURLOPT_INFILESIZE, $length);
     } else {
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, $file);
         $md5 = md5($file, true);
     }
     $this->headers['Content-MD5'] = base64_encode($md5);
     return $this;
 }
开发者ID:ericnorris,项目名称:amazon-s3-php,代码行数:17,代码来源:S3.php


注:本文中的hash_update_stream函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。