/** * Constructor * * @param io.streams.OutputStream out * @param int lineLength limit maximum line length */ public function __construct(OutputStream $out, $lineLength = 0) { $params = $lineLength ? array('line-length' => $lineLength, 'line-break-chars' => "\n") : array(); $this->out = Streams::writeableFd($out); if (!stream_filter_append($this->out, 'convert.base64-encode', STREAM_FILTER_WRITE, $params)) { throw new IOException('Could not append stream filter'); } }
/** * Constructor * * @param io.streams.OutputStream out * @param int level default 6 * @throws lang.IllegalArgumentException if the level is not between 0 and 9 */ public function __construct(OutputStream $out, $level = 6) { if ($level < 0 || $level > 9) { throw new IllegalArgumentException('Level ' . $level . ' out of range [0..9]'); } $this->out = Streams::writeableFd($out); if (!stream_filter_append($this->out, 'zlib.deflate', STREAM_FILTER_WRITE, $level)) { fclose($this->out); $this->out = NULL; throw new IOException('Could not append stream filter'); } }
/** * Constructor * * @param io.streams.OutputStream out * @param int level default 6 * @throws lang.IllegalArgumentException if the level is not between 0 and 9 */ public function __construct(OutputStream $out, $level = 6) { if ($level < 0 || $level > 9) { throw new \lang\IllegalArgumentException('Level ' . $level . ' out of range [0..9]'); } $this->out = Streams::writeableFd($out); if (!stream_filter_append($this->out, 'bzip2.compress', STREAM_FILTER_WRITE, ['blocks' => $level])) { fclose($this->out); $this->out = null; throw new \io\IOException('Could not append stream filter'); } }
/** * Constructor * * @param io.streams.OutputStream out * @param int level default 6 * @throws lang.IllegalArgumentException if the level is not between 0 and 9 */ public function __construct(OutputStream $out, $level = 6) { if ($level < 0 || $level > 9) { throw new \lang\IllegalArgumentException('Level ' . $level . ' out of range [0..9]'); } // Write GZIP format header: // * ID1, ID2 (Identification, \x1F, \x8B) // * CM (Compression Method, 8 = deflate) // * FLG (Flags, use 0) // * MTIME (Modification time, Un*x timestamp) // * XFL (Extra flags, 2 = compressor used maximum compression) // * OS (Operating system, 255 = unknown) $out->write(pack('CCCCVCC', 0x1f, 0x8b, 8, 0, time(), 2, 255)); // Now, convert stream to file handle and append deflating filter $this->out = Streams::writeableFd($out); if (!($this->filter = stream_filter_append($this->out, 'zlib.deflate', STREAM_FILTER_WRITE, $level))) { fclose($this->out); $this->out = null; throw new \io\IOException('Could not append stream filter'); } $this->md = hash_init('crc32b'); }
public function set_contents_writes_bytes() { $out = new MemoryOutputStream(); FileUtil::setContents(new File(Streams::writeableFd($out)), 'Test'); $this->assertEquals('Test', $out->getBytes()); }
public function reading_from_writeable_fd_raises_exception() { $fd = Streams::writeableFd(new MemoryOutputStream()); fread($fd, 1024); }
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 readFromWriteableFd() { $fd = Streams::writeableFd(new MemoryOutputStream()); fread($fd, 1024); }
public function printStackTrace() { $out = new MemoryOutputStream(); $e = new Throwable('Test'); create($e)->printStackTrace(Streams::writeableFd($out)); $this->assertEquals($e->toString(), $out->getBytes()); }