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


PHP StreamInterface::seek方法代码示例

本文整理汇总了PHP中Psr\Http\Message\StreamInterface::seek方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamInterface::seek方法的具体用法?PHP StreamInterface::seek怎么用?PHP StreamInterface::seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Psr\Http\Message\StreamInterface的用法示例。


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

示例1: seek

 /**
  * {@inheritdoc}
  */
 public function seek($offset, $whence = SEEK_SET)
 {
     if ($whence == SEEK_SET) {
         return $this->decoratedStream->seek($offset + $this->offset, $whence);
     }
     return $this->decoratedStream->seek($offset, $whence);
 }
开发者ID:zendframework,项目名称:zend-diactoros,代码行数:10,代码来源:RelativeStream.php

示例2: toString

 /**
  * Converts an stream into an string and returns the result. The position of
  * the pointer will not change if the stream is seekable. Note this copies
  * the complete content of the stream into the memory
  *
  * @param \Psr\Http\Message\StreamInterface $stream
  * @return string
  */
 public static function toString(StreamInterface $stream)
 {
     if (!$stream->isReadable()) {
         return '';
     }
     if ($stream->isSeekable()) {
         $pos = $stream->tell();
         if ($pos > 0) {
             $stream->seek(0);
         }
         $content = $stream->getContents();
         $stream->seek($pos);
     } else {
         $content = $stream->getContents();
     }
     return $content;
 }
开发者ID:seytar,项目名称:psx,代码行数:25,代码来源:Util.php

示例3: testReadAndWrite

 public function testReadAndWrite()
 {
     $this->assertEquals(0, $this->stream->getSize());
     $this->stream->write("Hello World, And All Developers!");
     $this->assertEquals(32, $this->stream->getSize());
     // size
     $this->assertEquals(32, $this->stream->tell());
     // pointer
     $this->stream->rewind();
     $this->assertEquals(0, $this->stream->tell());
     $this->assertFalse($this->stream->eof());
     $this->assertEquals("Hell", $this->stream->read(4));
     $this->assertEquals("o World, ", $this->stream->read(9));
     $this->assertEquals("And All Developers!", $this->stream->getContents());
     $this->assertTrue($this->stream->eof());
     $this->stream->seek(12);
     $this->assertEquals(6, $this->stream->write('Hum...'));
     $this->assertEquals("ll Developers!", $this->stream->getContents());
     $this->assertEquals("Hello World,Hum...ll Developers!", $this->stream->__toString());
 }
开发者ID:Golpha,项目名称:Http,代码行数:20,代码来源:StreamTestTrait.php

示例4: cropContent

 private function cropContent(StreamInterface $stream = null)
 {
     if (null === $stream) {
         return '';
     }
     if ($stream->getSize() <= $this->maxBodySize) {
         return (string) $stream;
     }
     $stream->seek(0);
     return '(partial content)' . $stream->read($this->maxBodySize) . '(...)';
 }
开发者ID:rolebi,项目名称:CsaGuzzleBundle,代码行数:11,代码来源:GuzzleCollector.php

示例5: hash

/**
 * Calculate a hash of a Stream
 *
 * @param StreamInterface $stream    Stream to calculate the hash for
 * @param string          $algo      Hash algorithm (e.g. md5, crc32, etc)
 * @param bool            $rawOutput Whether or not to use raw output
 *
 * @return string Returns the hash of the stream
 * @throws \RuntimeException on error.
 */
function hash(StreamInterface $stream, $algo, $rawOutput = false)
{
    $pos = $stream->tell();
    if ($pos > 0) {
        $stream->rewind();
    }
    $ctx = hash_init($algo);
    while (!$stream->eof()) {
        hash_update($ctx, $stream->read(1048576));
    }
    $out = hash_final($ctx, (bool) $rawOutput);
    $stream->seek($pos);
    return $out;
}
开发者ID:drickferreira,项目名称:rastreador,代码行数:24,代码来源:functions.php

示例6: stream_seek

 public function stream_seek($offset, $whence)
 {
     $this->stream->seek($offset, $whence);
     return true;
 }
开发者ID:Rayac,项目名称:search,代码行数:5,代码来源:StreamWrapper.php

示例7: seek

 /**
  * {@inheritdoc}
  */
 public function seek($offset, $whence = SEEK_SET)
 {
     $this->stream->seek($offset, $whence);
 }
开发者ID:narrowspark,项目名称:framework,代码行数:7,代码来源:AbstractStreamDecorator.php

示例8: testWrapsWrites

 public function testWrapsWrites()
 {
     $this->b->seek(0, SEEK_END);
     $this->b->write('foo');
     $this->assertEquals('foofoo', (string) $this->a);
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:6,代码来源:StreamDecoratorTraitTest.php

示例9: addFileFromPsr7Stream

 /**
  * addFile_from_Psr7Stream
  * 
  * dds an open stream to the archive uncompressed
  *
  * @param String $name - path of file in archive (including directory).
  * @param Resource $stream - contents of file as a stream resource
  * @param array $opt - Hash of options for file (optional, see "File Options" below).
  * 
  * File Options:
  *  time     - Last-modified timestamp (seconds since the epoch) of
  *             this file.  Defaults to the current time.
  *  comment  - Comment related to this file.
  *
  * Examples:
  *
  *   // create a temporary file stream and write text to it
  *   $fp = tmpfile();
  *   fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
  *
  *   // add a file named 'streamfile.txt' from the content of the stream
  *   $x->addFile_from_stream('streamfile.txt', $fp);
  *
  * @return void
  */
 public function addFileFromPsr7Stream($name, \Psr\Http\Message\StreamInterface $stream, $opt = array())
 {
     $name = $this->filterFilename($name);
     $block_size = 1048576;
     // process in 1 megabyte chunks
     $algo = 'crc32b';
     $meth = static::METHOD_STORE;
     // calculate header attributes
     $stream->seek(0, SEEK_END);
     $zlen = $len = $stream->tell();
     // send file header
     $hlen = $this->addFileHeader($name, $opt, $meth);
     // Stream data and calculate CRC32
     $stream->rewind();
     $hash_ctx = hash_init($algo);
     while (!$stream->eof()) {
         $data = $stream->read($block_size);
         hash_update($hash_ctx, $data);
         // send data
         $this->send($data);
     }
     $crc = hexdec(hash_final($hash_ctx));
     // send file footer + CDR record
     $this->addFileFooter($name, $opt, $meth, $crc, $zlen, $len, $hlen);
 }
开发者ID:brokencube,项目名称:ZipStream64,代码行数:50,代码来源:ZipStream.php


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