/** * 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'); } }
/** * 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'); } }
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)); }
/** * 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; }
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'); }
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); }
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); }
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); }
/** * 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); }