• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP hash_update_stream函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: hash

 /**
  * see http://php.net/manual/en/function.hash.php
  *
  * @param string $type
  * @param string $path
  * @param bool $raw
  * @return string
  */
 public function hash($type, $path, $raw = false)
 {
     $fh = $this->fopen($path, 'rb');
     $ctx = hash_init($type);
     hash_update_stream($ctx, $fh);
     fclose($fh);
     return hash_final($ctx, $raw);
 }
开发者ID:enoch85,项目名称:owncloud-testserver,代码行数:16,代码来源:encryption.php


示例17: updateStream

 /**
  * @param resource $handle
  * @param int $length
  * @return int
  */
 public function updateStream($handle, $length = -1)
 {
     $hash = @hash_update_stream($this->context, $handle, $length);
     if (false === $hash) {
         throw new HashException();
     }
     return $hash;
 }
开发者ID:mleko,项目名称:hash,代码行数:13,代码来源:Hash.php


示例18: UnexpectedValueException

                 $write_dir($files, $path);
                 break;
             default:
                 throw new UnexpectedValueException(sprintf('The type "%d" for "%s" in "%s" is not recognized.', $path['type'], $path['path'], __FILE__));
         }
     }
 };
 /**
  * Checks if the signature is valid.
  *
  * @return boolean Returns `true` if it is, `false` if not.
  */
 $is_verified = function () use(&$signature, &$size) {
     $stream = fopen(__FILE__, 'rb');
     $context = hash_init('sha1');
     hash_update_stream($context, $stream, $size - 20);
     fclose($stream);
     return $signature === hash_final($context, true);
 };
 if (!is_dir($cache)) {
     if (!$is_verified()) {
         throw new RuntimeException(sprintf('The signature for "%s" is not valid.', __FILE__));
     }
     mkdir($cache, 0755, true);
     $extract_database();
     $extract_files();
 }
 restore_error_handler();
 if (is_file($primary)) {
     return "require '{$primary}';";
 }
开发者ID:sqon,项目名称:sqon,代码行数:31,代码来源:bootstrap.php


示例19: computeMoreFromStream

 /**
  * Computes more of the hash from a stream.
  *
  * @param  resource $stream The handle of an open stream.
  * @param  int $maxNumInputBytes **OPTIONAL. Default is** *determine automatically*. The maximum number of bytes
  * to be processed from the stream.
  *
  * @return int The actual number of bytes that were processed from the stream.
  */
 public function computeMoreFromStream($stream, $maxNumInputBytes = null)
 {
     assert('is_resource($stream) && (!isset($maxNumInputBytes) || is_int($maxNumInputBytes))', vs(isset($this), get_defined_vars()));
     if (!isset($maxNumInputBytes)) {
         return hash_update_stream($this->m_hashingContext, $stream);
     } else {
         return hash_update_stream($this->m_hashingContext, $stream, $maxNumInputBytes);
     }
 }
开发者ID:nunodotferreira,项目名称:Phred,代码行数:18,代码来源:CHash.php


示例20: upload

 /**
  * Uploads a file to a bucket and returns a File object.
  *
  * @param array $options
  * @return File
  */
 public function upload(array $options)
 {
     // Clean the path if it starts with /.
     if (substr($options['FileName'], 0, 1) === '/') {
         $options['FileName'] = ltrim($options['FileName'], '/');
     }
     if (!isset($options['BucketId']) && isset($options['BucketName'])) {
         $options['BucketId'] = $this->getBucketIdFromName($options['BucketName']);
     }
     // Retrieve the URL that we should be uploading to.
     $response = $this->client->request('POST', $this->apiUrl . '/b2_get_upload_url', ['headers' => ['Authorization' => $this->authToken], 'json' => ['bucketId' => $options['BucketId']]]);
     $uploadEndpoint = $response['uploadUrl'];
     $uploadAuthToken = $response['authorizationToken'];
     if (is_resource($options['Body'])) {
         // We need to calculate the file's hash incrementally from the stream.
         $context = hash_init('sha1');
         hash_update_stream($context, $options['Body']);
         $hash = hash_final($context);
         // Similarly, we have to use fstat to get the size of the stream.
         $size = fstat($options['Body'])['size'];
         // Rewind the stream before passing it to the HTTP client.
         rewind($options['Body']);
     } else {
         // We've been given a simple string body, it's super simple to calculate the hash and size.
         $hash = sha1($options['Body']);
         $size = mb_strlen($options['Body']);
     }
     if (!isset($options['FileLastModified'])) {
         $options['FileLastModified'] = round(microtime(true) * 1000);
     }
     if (!isset($options['FileContentType'])) {
         $options['FileContentType'] = 'b2/x-auto';
     }
     $response = $this->client->request('POST', $uploadEndpoint, ['headers' => ['Authorization' => $uploadAuthToken, 'Content-Type' => $options['FileContentType'], 'Content-Length' => $size, 'X-Bz-File-Name' => $options['FileName'], 'X-Bz-Content-Sha1' => $hash, 'X-Bz-Info-src_last_modified_millis' => $options['FileLastModified']], 'body' => $options['Body']]);
     return new File($response['fileId'], $response['fileName'], $response['contentSha1'], $response['contentLength'], $response['contentType'], $response['fileInfo']);
 }
开发者ID:cwhite92,项目名称:b2-sdk-php,代码行数:42,代码来源:Client.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP hashit函数代码示例发布时间:2022-05-15
下一篇:
PHP hash_update函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap