本文整理汇总了PHP中Streams::readableFd方法的典型用法代码示例。如果您正苦于以下问题:PHP Streams::readableFd方法的具体用法?PHP Streams::readableFd怎么用?PHP Streams::readableFd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Streams
的用法示例。
在下文中一共展示了Streams::readableFd方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param io.streams.InputStream in
*/
public function __construct(InputStream $in)
{
$this->in = Streams::readableFd($in);
if (!stream_filter_append($this->in, 'zlib.inflate', STREAM_FILTER_READ)) {
throw new IOException('Could not append stream filter');
}
}
示例2: __construct
/**
* Constructor
*
* @param io.streams.InputStream in
*/
public function __construct(InputStream $in)
{
$this->in = Streams::readableFd($in);
if (!stream_filter_append($this->in, 'bzip2.decompress', STREAM_FILTER_READ)) {
throw new \io\IOException('Could not append stream filter');
}
}
示例3: get_contents_read_returns_less_than_size
public function get_contents_read_returns_less_than_size()
{
$f = new File(Streams::readableFd(new class('Test') extends MemoryInputStream
{
public function read($size = 4096)
{
return parent::read(min(1, $size));
}
}));
$this->assertEquals('Test', FileUtil::getContents($f));
}
示例4: __construct
/**
* Constructor. Creates a new TextReader on an underlying input
* stream with a given charset.
*
* @param io.streams.InputStream stream
* @param string charset the charset the stream is encoded in or NULL to trigger autodetection by BOM
*/
public function __construct(InputStream $stream, $charset = NULL)
{
parent::__construct($stream);
$this->in = Streams::readableFd($stream);
if (NULL === $charset) {
$charset = $this->detectCharset();
}
if (!stream_filter_append($this->in, 'convert.iconv.' . $charset . '/' . xp::ENCODING, STREAM_FILTER_READ)) {
throw new IOException('Could not append stream filter');
}
$this->charset = $charset;
}
示例5: boxResource
public function boxResource()
{
$fd = Streams::readableFd(new MemoryInputStream('test'));
try {
Primitive::boxed($fd);
} catch (IllegalArgumentException $expected) {
// OK
}
ensure($expected);
fclose($fd);
// Necessary, PHP will segfault otherwise
if ($expected) {
return;
}
$this->fail('Expected exception not caught', NULL, 'lang.IllegalArgumentException');
}
示例6: read_while_not_eof
public function read_while_not_eof()
{
$fd = Streams::readableFd(new MemoryInputStream(str_repeat('x', 1024)));
$l = [];
while (!feof($fd)) {
$c = fread($fd, 128);
$l[] = strlen($c);
}
fclose($fd);
$this->assertEquals([128, 128, 128, 128, 128, 128, 128, 128], $l);
}
示例7: creating_archive
public function creating_archive()
{
$contents = ['lang/Object.class.php' => '<?php class Object { }', 'lang/Type.class.php' => '<?php class Type extends Object { }'];
$out = new MemoryOutputStream();
$a = new Archive(new File(Streams::writeableFd($out)));
$a->open(Archive::CREATE);
foreach ($contents as $filename => $bytes) {
$a->addBytes($filename, $bytes);
}
$a->create();
$file = new File(Streams::readableFd(new MemoryInputStream($out->getBytes())));
$this->assertEntries(new Archive($file), $contents);
}
示例8: whileNotEof
public function whileNotEof()
{
$fd = Streams::readableFd(new MemoryInputStream(str_repeat('x', 1024)));
$l = array();
while (!feof($fd)) {
$c = fread($fd, 128);
$l[] = strlen($c);
}
fclose($fd);
$this->assertEquals(array(128, 128, 128, 128, 128, 128, 128, 128), $l);
}
示例9: newStream
/**
* Returns a new EncapsedStream instance
*
* @return io.EncapsedStream
*/
public function newStream($contents = '', $start = 0, $length = 0)
{
return new EncapsedStream(new File(Streams::readableFd(new MemoryInputStream($contents))), $start, $length);
}