/** * Constructor * * @param io.streams.InputStream in */ public function __construct(InputStream $in) { $this->in = Streams::readableFd($in); if (!stream_filter_append($this->in, 'convert.base64-decode', 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(newinstance(MemoryInputStream::class, ['Test'], ['read' => function ($size = 4096) { return parent::read(min(1, $size)); }]))); $this->assertEquals('Test', FileUtil::getContents($f)); }
public function boxResource() { $fd = Streams::readableFd(new MemoryInputStream('test')); try { Primitive::boxed($fd); } catch (IllegalArgumentException $expected) { return; } finally { fclose($fd); // Necessary, PHP will segfault otherwise } $this->fail('Expected exception not caught', null, 'lang.IllegalArgumentException'); }
/** * Creates a new fixture * * @param string $str * @return org.yaml.Input */ protected function newFixture($str = '') { return new FileInput(new File(Streams::readableFd(new MemoryInputStream($str)))); }
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); }
/** * 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); }