/**
  * Reads stream contents
  *
  * @param   io.streams.InputStream is
  * @return  string bytes
  */
 protected function readAll(InputStream $is)
 {
     for ($contents = ''; $is->available();) {
         $contents .= $is->read();
     }
     $is->close();
     return $contents;
 }
Ejemplo n.º 2
0
function reader(InputStream $stream)
{
    foreach ($stream as $line) {
        if (strlen($line)) {
            (yield $line);
        } else {
            $stream->close();
        }
    }
}
Ejemplo n.º 3
0
 /**
  * Read a line
  *
  * @param   io.streams.InputStream in
  * @return  string
  * @throws  lang.FormatException if no line can be read
  */
 protected function readLine(InputStream $in)
 {
     $line = '';
     while ("\n" !== ($chr = $in->read(1))) {
         $line .= $chr;
         if (!$in->available()) {
             break;
         }
     }
     return $line;
 }
Ejemplo n.º 4
0
 public static function _readInt(InputStream $stream, $length)
 {
     $result = 0;
     for ($i = 0; $i != $length; ++$i) {
         $b = $stream->readByte();
         if ($b == -1) {
             throw new EOFException();
         }
         $result |= $b << $i * 8;
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Upload to this file from an input stream
  *
  * @param   io.streams.InputStream in
  * @param   int mode default FtpTransfer::ASCII
  * @param   peer.ftp.FtpTransferListener listener default NULL
  * @return  peer.ftp.FtpFile this file
  * @throws  peer.SocketException in case of an I/O error
  */
 public function uploadFrom(InputStream $in, $mode = FtpTransfer::ASCII, FtpTransferListener $listener = NULL)
 {
     $transfer = create(new FtpUpload($this, $in))->withListener($listener)->start($mode);
     while (!$transfer->complete()) {
         $transfer->perform();
     }
     if ($transfer->aborted()) {
         throw new SocketException(sprintf('Transfer from %s to %s (mode %s) was aborted', $in->toString(), $this->name, $mode));
     }
     $this->refresh('upload');
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Construct a new FileInputStream.
  * @param mixed $file
  * @throws Exception - if invalid argument specified.
  * @throws IOException - if unable to open file.
  */
 public function __construct($file, $append = false)
 {
     if ($file instanceof PhingFile) {
         $this->file = $file;
     } elseif (is_string($file)) {
         $this->file = new PhingFile($file);
     } else {
         throw new Exception("Invalid argument type for \$file.");
     }
     $stream = @fopen($this->file->getAbsolutePath(), "rb");
     if ($stream === false) {
         throw new IOException("Unable to open " . $this->file->__toString() . " for reading: " . $php_errormsg);
     }
     parent::__construct($stream);
 }
 /**
  * Constructor
  *
  * @param   io.streams.InputStream in
  */
 public function __construct(InputStream $in)
 {
     // Read GZIP format header
     // * ID1, ID2 (Identification, \x1F, \x8B)
     // * CM       (Compression Method, 8 = deflate)
     // * FLG      (Flags)
     // * MTIME    (Modification time, Un*x timestamp)
     // * XFL      (Extra flags)
     // * OS       (Operating system)
     $header = unpack('a2id/Cmethod/Cflags/Vtime/Cextra/Cos', $in->read(10));
     if ("‹" != $header['id']) {
         throw new IOException('Invalid format, expected \\037\\213, have ' . addcslashes($header['id'], "..ÿ"));
     }
     if (8 != $header['method']) {
         throw new IOException('Unknown compression method #' . $header['method']);
     }
     // Now, convert stream to file handle and append inflating filter
     $wri = 'zlib.bounded://' . $in->hashCode();
     self::$wrapped[$wri] = $in;
     $this->in = fopen($wri, 'r');
     if (!stream_filter_append($this->in, 'zlib.inflate', STREAM_FILTER_READ)) {
         throw new IOException('Could not append stream filter');
     }
 }
Ejemplo n.º 8
0
 /**
  * Returns string representation of attached stream.
  * @return string
  */
 public function getResource()
 {
     return $this->inStream->__toString();
 }
Ejemplo n.º 9
0
 /**
  * Returns whether the input is closed.
  *
  * @return bool Returns `true` if the input is closed and `false`
  *              otherwise.
  */
 public function isClosed()
 {
     return $this->stream->isClosed();
 }
Ejemplo n.º 10
0
 /**
  * Read an IOElements' contents completely into a buffer in a single call.
  *
  * @param   io.streams.InputStream s
  * @return  string
  * @throws  io.IOException
  */
 public static function readAll(InputStream $s)
 {
     $r = '';
     while ($s->available() > 0) {
         $r .= $s->read();
     }
     return $r;
 }
Ejemplo n.º 11
0
 public function available()
 {
     return $this->m_stream->available();
 }
Ejemplo n.º 12
0
 public function __construct()
 {
     parent::__construct(fopen('php://stdin', 'r'));
 }
Ejemplo n.º 13
0
 /**
  * @return bool
  */
 protected function isComment()
 {
     return $this->input->peek() == '-' && !$this->input->eof(1) && $this->input->peek(1) == '-';
 }