/**
  * Constructor
  *
  * @param   io.streams.InputStream $in
  * @throws  io.IOException
  */
 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)
     $this->header = unpack('a2id/Cmethod/Cflags/Vtime/Cextra/Cos', $in->read(10));
     if ("‹" != $this->header['id']) {
         throw new IOException('Invalid format, expected \\037\\213, have ' . addcslashes($this->header['id'], "..ÿ"));
     }
     if (8 !== $this->header['method']) {
         throw new IOException('Unknown compression method #' . $this->header['method']);
     }
     if (8 === ($this->header['flags'] & 8)) {
         $this->header['filename'] = '';
         while ("" !== ($b = $in->read(1))) {
             $this->header['filename'] .= $b;
         }
     }
     // 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');
     }
 }
 /**
  * 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.º 3
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 = (new FtpUpload($this, $in))->withListener($listener)->start($mode);
     while (!$transfer->complete()) {
         $transfer->perform();
     }
     if ($transfer->aborted()) {
         throw new \peer\SocketException(sprintf('Transfer from %s to %s (mode %s) was aborted', $in->toString(), $this->name, $mode));
     }
     $this->refresh('upload');
     return $this;
 }
Ejemplo n.º 4
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;
 }