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


PHP StreamInterface::tell方法代码示例

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


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

示例1: testSeeksAndTells

 public function testSeeksAndTells()
 {
     $this->b->seek(1);
     $this->assertEquals(1, $this->a->tell());
     $this->assertEquals(1, $this->b->tell());
     $this->b->seek(0);
     $this->assertEquals(0, $this->a->tell());
     $this->assertEquals(0, $this->b->tell());
     $this->b->seek(0, SEEK_END);
     $this->assertEquals(3, $this->a->tell());
     $this->assertEquals(3, $this->b->tell());
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:12,代码来源:StreamDecoratorTraitTest.php

示例2: 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

示例3: getChars

 /**
  * Get the chars from the blob
  *
  * @param $n Number of characters needed
  * @return string|null
  */
 public function getChars($n)
 {
     $response = null;
     // do we need more data?
     if ($this->strpos + $n - 1 >= strlen($this->str)) {
         $end = $this->strpos + $n;
         while (strlen($this->str) < $end && $response !== false) {
             // read more from the file handle
             $need = $end - $this->stream->tell();
             if ($response = $this->stream->read($need)) {
                 $this->str .= $response;
             } else {
                 return null;
             }
         }
     }
     $result = substr($this->str, $this->strpos, $n);
     $this->strpos += $n;
     // we are dealing with bytes here, so force the encoding
     return $result;
 }
开发者ID:nazieb,项目名称:flashimage,代码行数:27,代码来源:StreamWalker.php

示例4: 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

示例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_tell

 public function stream_tell()
 {
     return $this->stream->tell();
 }
开发者ID:Rayac,项目名称:search,代码行数:4,代码来源:StreamWrapper.php

示例7: tell

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

示例8: 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::tell方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。