本文整理汇总了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);
}
示例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;
}
示例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());
}
示例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) . '(...)';
}
示例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;
}
示例6: stream_seek
public function stream_seek($offset, $whence)
{
$this->stream->seek($offset, $whence);
return true;
}
示例7: seek
/**
* {@inheritdoc}
*/
public function seek($offset, $whence = SEEK_SET)
{
$this->stream->seek($offset, $whence);
}
示例8: testWrapsWrites
public function testWrapsWrites()
{
$this->b->seek(0, SEEK_END);
$this->b->write('foo');
$this->assertEquals('foofoo', (string) $this->a);
}
示例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);
}