/**
  * 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;
 }
Пример #3
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;
 }